Select to view content in your preferred language

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

3674
14
11-18-2011 11:01 AM
DanDong
Deactivated User
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
GregoryDillon
Occasional Contributor
I really need feet all the time.    Can this be fixed for 3.0?   Also is there a way to make the scalebar stay the same size.    The target width does not work like the old Scalebar.    It varies in size, the TargetWidth seems to indicate the Maximuim width rather than a fixed width.   Adjusting the Min/Max width does not help since this only adjusts the container not the scalebar itself.
0 Kudos
DominiqueBroux
Esri Frequent Contributor

I really need feet all the time.


You can get the sources on codeplex and tweak them for your need.
0 Kudos
LanceCrumbliss
Frequent Contributor
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:


Using this template shows different lengths from those in the default scaleline (v2.4).  for me at least.  attached is an image showing the templated scaleline posted above and the default scaleline rendered on top of each other.  The use the same units, but the scales they indicate are different.

[ATTACH=CONFIG]15508[/ATTACH]
0 Kudos
DominiqueBroux
Esri Frequent Contributor
To get result in feet, you also need to change this binding : Width="{Binding MetricSize, RelativeSource={RelativeSource TemplatedParent}}"> from MetricSize to USSize.

Did you do it?
0 Kudos
LanceCrumbliss
Frequent Contributor
Grr, no.  I had changed the text binding but not the width.  That makes too much sense. 

All is well now, thanks D.

Lance
0 Kudos