Yes, you can get it to look as the ScaleBar. The old scalebar style is just a particular case of the new scaleline control.The sample is given in the documentation.Define a scaleline style such as : <Style x:Key="ScaleBarStyle" TargetType="esri:ScaleLine"> <Setter Property="Background" Value="White"/> <Setter Property="TargetWidth" Value="150.0"/> <Setter Property="FontSize" Value="10.0"/> <Setter Property="Foreground" Value="Black"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="esri:ScaleLine"> <StackPanel Name="LayoutRoot" Orientation="Horizontal"> <Grid VerticalAlignment="Center" Height="10" Width="{Binding MetricSize, RelativeSource={RelativeSource TemplatedParent}}"> <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 Fill="{TemplateBinding Foreground}" Grid.Row="0" Grid.Column="0"/> <Rectangle Fill="{TemplateBinding Background}" Grid.Row="0" Grid.Column="1"/> <Rectangle Fill="{TemplateBinding Foreground}" Grid.Row="0" Grid.Column="2"/> <Rectangle Fill="{TemplateBinding Background}" Grid.Row="0" Grid.Column="3"/> <Rectangle Fill="{TemplateBinding Foreground}" Grid.Row="0" Grid.Column="4"/> <Rectangle Fill="{TemplateBinding Background}" Grid.Row="1" Grid.Column="0"/> <Rectangle Fill="{TemplateBinding Foreground}" Grid.Row="1" Grid.Column="1"/> <Rectangle Fill="{TemplateBinding Background}" Grid.Row="1" Grid.Column="2"/> <Rectangle Fill="{TemplateBinding Foreground}" Grid.Row="1" Grid.Column="3"/> <Rectangle Fill="{TemplateBinding Background}" Grid.Row="1" Grid.Column="4"/> </Grid> <TextBlock Text="{Binding MetricValue, RelativeSource={RelativeSource TemplatedParent}}" VerticalAlignment="Center" Margin="2,0"/> <TextBlock Text="{Binding MetricUnit, RelativeSource={RelativeSource TemplatedParent}}" VerticalAlignment="Center"/> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> Then you can use it with code like : <esri:ScaleLine Map="{Binding ElementName=MyMap}" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Bottom" Style="{StaticResource ScaleBarStyle}" /> and you get this kind of scaleline:
<Style x:Key="ScaleBarStyle" TargetType="esri:ScaleLine"> <Setter Property="Background" Value="White"/> <Setter Property="TargetWidth" Value="150.0"/> <Setter Property="FontSize" Value="10.0"/> <Setter Property="Foreground" Value="Black"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="esri:ScaleLine"> <StackPanel Name="LayoutRoot" Orientation="Horizontal"> <Grid VerticalAlignment="Center" Height="10" Width="{Binding MetricSize, RelativeSource={RelativeSource TemplatedParent}}"> <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 Fill="{TemplateBinding Foreground}" Grid.Row="0" Grid.Column="0"/> <Rectangle Fill="{TemplateBinding Background}" Grid.Row="0" Grid.Column="1"/> <Rectangle Fill="{TemplateBinding Foreground}" Grid.Row="0" Grid.Column="2"/> <Rectangle Fill="{TemplateBinding Background}" Grid.Row="0" Grid.Column="3"/> <Rectangle Fill="{TemplateBinding Foreground}" Grid.Row="0" Grid.Column="4"/> <Rectangle Fill="{TemplateBinding Background}" Grid.Row="1" Grid.Column="0"/> <Rectangle Fill="{TemplateBinding Foreground}" Grid.Row="1" Grid.Column="1"/> <Rectangle Fill="{TemplateBinding Background}" Grid.Row="1" Grid.Column="2"/> <Rectangle Fill="{TemplateBinding Foreground}" Grid.Row="1" Grid.Column="3"/> <Rectangle Fill="{TemplateBinding Background}" Grid.Row="1" Grid.Column="4"/> </Grid> <TextBlock Text="{Binding MetricValue, RelativeSource={RelativeSource TemplatedParent}}" VerticalAlignment="Center" Margin="2,0"/> <TextBlock Text="{Binding MetricUnit, RelativeSource={RelativeSource TemplatedParent}}" VerticalAlignment="Center"/> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style>
<esri:ScaleLine Map="{Binding ElementName=MyMap}" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Bottom" Style="{StaticResource ScaleBarStyle}" />
I really need feet all the time.
One more question: how do I control the units it displays? I can set english vs. metric, but what if I always want it to display feet?
Yes, this was marked obsolete in 2.2 when ScaleLine was introduced: http://help.arcgis.com/en/webapi/silverlight/2.2/help/index.html#/What_s_new_in_2_2/0166000000m2000000/ and deprecated in 2.3: http://help.arcgis.com/en/webapi/silverlight/help/index.html#//0166000000mm000000
private void UnitCombo_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (SetUnitBorder.Visibility == System.Windows.Visibility.Visible) { string _unit = UnitsCombo.SelectedItem.ToString(); if (_unit == "FEET") MyScaleBar.DisplayUnit = ScaleBarUnit.Feet; else if (_unit == "MILES") MyScaleBar.DisplayUnit = ScaleBarUnit.Miles; else if (_unit == "METERS") MyScaleBar.DisplayUnit = ScaleBarUnit.Meters; else if (_unit == "KILOMETERS") MyScaleBar.DisplayUnit = ScaleBarUnit.Kilometers; } }
The ScaleLine really seems to be a step backwards. Is there any way (i.e. an ACTUAL EXAMPLE) to get it to look and behave the way the ScaleBar did?
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.