label on demand

368
1
06-04-2012 02:13 PM
YassineEL_JADIDI
New Contributor
Hello,
i want to make an option on my application that show the labels of features on demand, for example a checkbox that show or hide the labels.
any idea about that please ?
0 Kudos
1 Reply
JenniferNery
Esri Regular Contributor
You can take a look at this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#CustomSymbols.

Specifically this code, you can use a different element here and set to a different attribute field, depending on the service.
 <esri:SimpleRenderer x:Key="MapTipLabelMarkerRendderer">
    <esri:SimpleRenderer.Symbol>
     <esri:MarkerSymbol OffsetX="6" OffsetY="6">
      <esri:MarkerSymbol.ControlTemplate>
       <ControlTemplate>
        <Grid>
         <VisualStateManager.VisualStateGroups>
          <VisualStateGroup x:Name="CommonStates">
           <VisualState x:Name="MouseOver">
            <Storyboard>
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="labelOnHover" 
                            Storyboard.TargetProperty="Visibility" 
                            Duration="0">
              <DiscreteObjectKeyFrame KeyTime="0">
               <DiscreteObjectKeyFrame.Value>
                <Visibility>Visible</Visibility>
               </DiscreteObjectKeyFrame.Value>
              </DiscreteObjectKeyFrame>
             </ObjectAnimationUsingKeyFrames>
             <DoubleAnimation From="0" To="1" Storyboard.TargetName="labelOnHover" 
                             Storyboard.TargetProperty="Opacity"
                             Duration="0:0:.25" />
            </Storyboard>
           </VisualState>
           <VisualState x:Name="Normal" />
          </VisualStateGroup>
         </VisualStateManager.VisualStateGroups>
         <!--Marker-->
         <Ellipse Width="12" Height="12" Fill="Red" 
                                     HorizontalAlignment="Left" VerticalAlignment="Top" />
         <!--Label-->
         <Grid Margin="8,-8,0,0" x:Name="labelOnHover" Visibility="Collapsed"
                        HorizontalAlignment="Left" VerticalAlignment="Top" >
          <!--Text halo using a white blurred text-->
          <TextBlock Foreground="White" FontWeight="Bold" Text="{Binding Attributes[AREANAME]}" >
                    <TextBlock.Effect>
                              <BlurEffect Radius="5" />
                    </TextBlock.Effect>
          </TextBlock>
          <!--Text-->
          <TextBlock Foreground="Black" FontWeight="Bold" Text="{Binding Attributes[AREANAME]}" />
         </Grid>
        </Grid>
       </ControlTemplate>
      </esri:MarkerSymbol.ControlTemplate>
     </esri:MarkerSymbol>
    </esri:SimpleRenderer.Symbol>
   </esri:SimpleRenderer>
0 Kudos