Scalebar has some issue in 2.2, is it replaced by scaleline?

2789
14
11-18-2011 11:01 AM
DanDong
New Contributor
Hi everyone,

After update ESRI's sl api reference from 2.1 to 2.2, will scalebar be affected since we get the following warning. And in esri's sl latest sample, scalebas is replaced by scaleline. But from the sl api reference, scalebar is still under ESRI.ArcGIS.Client class.

'ESRI.ArcGIS.Client.ScaleBar' is obsolete: 'Use ScaleLine control in ESRI.ArcGIS.Client.Toolkit namespace.'
0 Kudos
14 Replies
JenniferNery
Esri Regular Contributor
0 Kudos
MarkCederholm
Occasional Contributor III
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?
0 Kudos
DominiqueBroux
Esri Frequent Contributor

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?

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:
0 Kudos
MarkCederholm
Occasional Contributor III
Thanks, I had only seen the first example in the docs and not the second.
0 Kudos
MarkCederholm
Occasional Contributor III
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?
0 Kudos
DanDong
New Contributor
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?


Hi Mark,

Not sure this is what you want. Below is the code I use for scalebar to change the display unit with a combobox.

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;
            }
        }
0 Kudos
DanDong
New Contributor
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/0166000000m20000... and deprecated in 2.3: http://help.arcgis.com/en/webapi/silverlight/help/index.html#//0166000000mm000000


Thank you Jennifer. So if I update the reference to 2.2 and I still use scalebar, instead of scaleline, is there any issue it may cause?
0 Kudos
JenniferNery
Esri Regular Contributor
There should not be a problem in 2.2. Here's the SDK sample in 2.2 that use Scalebar:http://help.arcgis.com/en/webapi/silverlight/2.2/samples/start.htm#Scalebar
0 Kudos
DominiqueBroux
Esri Frequent Contributor

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?


You can't.
When you use US units, the units will be automatically Miles or Feet depending on the rounded scale value to display (i.e. depending on the scale).
0 Kudos