Select to view content in your preferred language

ScaleLine control hide US units

713
1
01-31-2012 10:42 PM
DavideLimosani
Frequent Contributor
hi all,

I have a noob question for you. How can I hide the US units on the ScaleLine? I'd like to keep only meters and kilometers. I don't think that the API reference is clear on this point, but probably I'm missing something.

Thank you in advance!

Davide
0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
How can I hide the US units on the ScaleLine?


You have to change the style of the scaleline.

For example, here is a ScaleLine template showing only Metrics Units, localizing the units and displaying the text in the center of the scale line:
<esri:ScaleLine.Template>
    <ControlTemplate TargetType="esri:ScaleLine">
        <Grid x:Name="LayoutRoot">
            <Grid.Resources>
                <converters:ObjectToObjectConverter x:Key="UnitsConverter">
                    <ResourceDictionary>
                        <sys:String x:Key="Meters">Métres</sys:String>
                        <sys:String x:Key="Kilometers">Kilométres</sys:String>
                    </ResourceDictionary>
                </converters:ObjectToObjectConverter>
            </Grid.Resources>
            <StackPanel HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" >
                <StackPanel x:Name="MetricNotchs" Orientation="Horizontal">
                    <Rectangle x:Name="LeftTopNotch" Width="2" Fill="{TemplateBinding Foreground}" Height="5" Stroke="{TemplateBinding Foreground}" VerticalAlignment="Bottom" />
                    <Grid Width="{Binding MetricSize, RelativeSource={RelativeSource TemplatedParent}}">
                        <StackPanel x:Name="MetricText" Orientation="Horizontal" HorizontalAlignment="Center" >
                            <TextBlock Text="{Binding MetricValue, RelativeSource={RelativeSource TemplatedParent}}"/>
                            <TextBlock Text="{Binding MetricUnit, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource UnitsConverter}}"/>
                        </StackPanel>
                    </Grid>
                    <Rectangle x:Name="RightTopNotch" Width="2" Fill="{TemplateBinding Foreground}" Height="5" Stroke="{TemplateBinding Foreground}" VerticalAlignment="Bottom"/>
                </StackPanel>
                <StackPanel x:Name="ScaleLineBlock" Orientation="Horizontal">
                    <Rectangle x:Name="NotchsWidth" Fill="{TemplateBinding Foreground}" Height="2" Stroke="{TemplateBinding Foreground}" Width="4"/>
                    <Rectangle Fill="{TemplateBinding Foreground}" Height="2" Stroke="{TemplateBinding Foreground}" Margin="0" HorizontalAlignment="Left" 
                                Width="{Binding MetricSize, RelativeSource={RelativeSource TemplatedParent}}" />
                </StackPanel>
                <StackPanel x:Name="BottomNotchs" Orientation="Horizontal">
                    <Rectangle x:Name="LeftBottomNotch" Width="2" Fill="{TemplateBinding Foreground}" Height="5" Stroke="{TemplateBinding Foreground}" VerticalAlignment="Top" />
                    <Grid x:Name="PaddingLeftBottomNotch" Width="{Binding MetricSize, RelativeSource={RelativeSource TemplatedParent}}" />
                    <Rectangle x:Name="RightBottomNotch" Width="2" Fill="{TemplateBinding Foreground}" Height="5"  Stroke="{TemplateBinding Foreground}" VerticalAlignment="Top"/>
                </StackPanel>
            </StackPanel>
        </Grid>
    </ControlTemplate>
</esri:ScaleLine.Template>
0 Kudos