Adding a Mode Button

Lets add a button:

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

Missouri

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”>
<Grid.RowDefinitions>
<RowDefinition Height=”24*”/>
<RowDefinition Height=”395*”/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=”62*”/>
<ColumnDefinition Width=”555*”/>
</Grid.ColumnDefinitions>
<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;
}
else
{
myMap.Mode = new RoadMode();
MyMode = 0;
}
}

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

NashvilleRoadNashville

 

 

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s