<Style x:Key="ScaleBarStyle" TargetType="esri:ScaleBar"> <Setter Property="FillColor1" Value="White"/> <Setter Property="FillColor2" Value="Black"/> <Setter Property="TextColor" Value="White"/> <Setter Property="TargetWidth" Value="150.0"/> <Setter Property="FontSize" Value="10.0"/> <Setter Property="BarHeight" Value="10.0"/> <Setter Property="Foreground" Value="White"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="esri:ScaleBar"> <StackPanel Orientation="Horizontal"> <Grid x:Name="ScaleBarBlock" Height="{TemplateBinding BarHeight}" VerticalAlignment="Center"> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*"/> <ColumnDefinition Width="1*"/> <ColumnDefinition Width="1*"/> <ColumnDefinition Width="2*"/> <ColumnDefinition Width="5*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="1*"/> <RowDefinition Height="1*"/> </Grid.RowDefinitions> <Rectangle Grid.Column="0" Fill="{TemplateBinding FillColor2}" Grid.Row="0"/> <Rectangle Grid.Column="1" Fill="{TemplateBinding FillColor1}" Grid.Row="0"/> <Rectangle Grid.Column="2" Fill="{TemplateBinding FillColor2}" Grid.Row="0"/> <Rectangle Grid.Column="3" Fill="{TemplateBinding FillColor1}" Grid.Row="0"/> <Rectangle Grid.Column="4" Fill="{TemplateBinding FillColor2}" Grid.Row="0"/> <Rectangle Grid.Column="0" Fill="{TemplateBinding FillColor1}" Grid.Row="1"/> <Rectangle Grid.Column="1" Fill="{TemplateBinding FillColor2}" Grid.Row="1"/> <Rectangle Grid.Column="2" Fill="{TemplateBinding FillColor1}" Grid.Row="1"/> <Rectangle Grid.Column="3" Fill="{TemplateBinding FillColor2}" Grid.Row="1"/> <Rectangle Grid.Column="4" Fill="{TemplateBinding FillColor1}" Grid.Row="1"/> </Grid> <TextBlock x:Name="ScaleBarValue" Loaded="ScaleBarValue_Loaded" Foreground="{TemplateBinding TextColor}" VerticalAlignment="Center"/> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style>
TextBlock scaleBarValue; private void ScaleBarValue_Loaded(object sender, RoutedEventArgs e) { scaleBarValue = sender as TextBlock; } private void MyMap_ExtentChanged(object sender, ESRI.ArcGIS.Client.ExtentEventArgs e) { //check for scaleBarValue.Text }
private void ScaleBar_Loaded(object sender, RoutedEventArgs e) { ScaleBar.ApplyTemplate(); ScaleBarValueTextBlock = ScaleBar.Template.FindName("ScaleBarValue", ScaleBar) as TextBlock; } private void Map_ExtentChanged(object sender, ESRI.ArcGIS.Client.ExtentEventArgs e) { if (ScaleBarValueTextBlock != null) { if (ScaleBar.DisplayUnit == ScaleBarUnit.Miles && ScaleBarValueTextBlock.Text[0] == '0') ScaleBar.DisplayUnit = ScaleBarUnit.Feet; else if (ScaleBar.DisplayUnit == ScaleBarUnit.Feet && Convert.ToDouble(ScaleBarValueTextBlock.Text.TrimEnd(" Feet".ToCharArray())) > 5279) ScaleBar.DisplayUnit = ScaleBarUnit.Miles; } }
Also, if the API developers don't have an issue with it, maybe in a future version could make the actual double value property public and read-only to the users?
string stringValue = ScaleBarValueTextBlock.Text.Replace(ScaleBar.DisplayUnit.ToString(), string.Empty).Trim(); double doubleValue = Convert.ToDouble(stringValue, CultureInfo.InvariantCulture); // or this below //double doubleValue = double.IsNaN; //double.TryParse(stringValue, out doubleValue);