The view has two buttons, which are bound to the viewmodel’s StartCommand
and StopCommand
(see Listing 17.7).
The GeoLocationView
contains several TextBlock
elements that are bound to viewmodel properties.
A Slider
is bound to the viewmodel’s SampleIntervalMs
property, allowing the user to control the sample frequency. The sampling feature is explored later in the chapter.
A Windows Phone Toolkit ToggleSwitch
is bound to the viewmodel’s UseMockLocator
property and changes the IGeoLocator
implementation that is used during tracking.
<StackPanel Grid.Row="1" Margin="21,30,21,0">
<StackPanel Grid.Row="1" Margin="21,0,21,0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60" />
<RowDefinition Height="60" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="latitude"
Style="{StaticResource LatLongTitleStyle}"
VerticalAlignment="Center" />
<TextBlock Text="{Binding GeoCoordinate.Latitude, StringFormat={0:F4}}"
Style="{StaticResource LatLongStyle}"
Grid.Row="1"/>
<TextBlock Text="longitude"
Style="{StaticResource LatLongTitleStyle}"
Grid.Column="1" VerticalAlignment="Center" />
<TextBlock Text="{Binding GeoCoordinate.Longitude, StringFormat={0:F4}}"
Style="{StaticResource LatLongStyle}"
Grid.Row="1" Grid.Column="1" />
</Grid>
<TextBlock Text="{Binding PositionStatus}"
Style="{StaticResource PhoneTextNormalStyle}"
Foreground="{StaticResource PhoneAccentBrush}"
Height="50" Margin="0" />
<TextBlock Text="sample interval in milliseconds (0 for realtime)"
Style="{StaticResource LabelTextStyle}"
FontSize="{StaticResource PhoneFontSizeSmall}"/>
<Slider Minimum="0"
Maximum="10000"
Value="{Binding SampleIntervalMs, Mode=TwoWay}"
IsEnabled="{Binding CanStart}"
LargeChange="1000" SmallChange="1000"/>
<TextBlock Text="{Binding SampleIntervalMs}" Width="100" Height="50"
HorizontalAlignment="Left"
Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="{Binding Message}" Height="50"
Style="{StaticResource PhoneTextNormalStyle}"/>
<toolkit:ToggleSwitch Header="mock locator"
IsChecked="{Binding UseMockLocator, Mode=TwoWay}"
IsEnabled="{Binding CanStart}"/>
<StackPanel Orientation="Horizontal">
<Button Content="Start"
Command="{Binding StartCommand}"
Margin="0,20,0,0" Width="150" HorizontalAlignment="Left"/>
<Button Content="Stop"
Command="{Binding StopCommand}"
Margin="0,20,0,0" Width="150" HorizontalAlignment="Left"/>
</StackPanel>
</StackPanel>
Tapping the Start button causes the current location to be displayed whenever the IGeoLocator
object’s PositionChanged
event is raised (see Figure 17.6).
The OS displays an indicator in the system tray when location tracking is engaged. In the sample this occurs when the mock locator is turned off.
3.138.124.143