Adding a Mode Button

Lets add a button:

<Button x:Name=”btMode” Content=”Mode”  Margin=”1,1,0,5″ Click=”btMode_Click” />


To do this we first need to make some changes to the xaml.   Here’s the code:

<Grid Margin=”0,0,0,0″ Background=”#FF43B08B”>
<RowDefinition Height=”24*”/>
<RowDefinition Height=”395*”/>
<ColumnDefinition Width=”62*”/>
<ColumnDefinition Width=”555*”/>
<Button x:Name=”btMode” Content=”Mode” Margin=”1,1,0,5″ Click=”btMode_Click” />

We now need the the code behind to make it work .  First we are going to have to add a variable to let us know what state our map is currently in.  So why don’t we just add this:

public partial class MainWindow : Window
public int MyMode = 0;
to the top MainWindow method.  That will give us a variable to use to keep track of our current mode.  Now in the click event we just created for the button. We will add the following code.
private void btMode_Click(object sender, RoutedEventArgs e)
if (MyMode == 0)
myMap.Mode = new AerialMode();
MyMode = 1;
myMap.Mode = new RoadMode();
MyMode = 0;

That will give us the ability to switch back and forth.





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s