Select to view content in your preferred language

Programmatic access to Map Table of Contents, or any other OOTB control

3151
4
11-28-2013 06:53 AM
DannyVenier
Deactivated User
Hi,

I'm working on an application based on Silverlight viewer. I'm trying to implement additional controls that interact with the "out of the box" table of contents. For example, I'd like another control to open and close the TOC.

The challenge is to get a reference to the TOC object so that I can work with it. I can look in the layout, find the TOC container (TabItem in TabControl) and make visible or collapsed, or access it's defined states/storyboard. For the feature to just open and close the TOC from another control, I'm finding that making it's TabItem visible does not show the TOC. It will after I've used the OOTB button, which may initialize the TOC control, not sure. After using the OOTB button once, my control is able to open (make visible) and close (make collapsed) but unless I first open it with the OOTB command button, I just get an invisible layout object (I think it's the tabItem with no content opening up because it pushes the navigator control out to the right of its space.

So the general question is...how can one get programmatic references to the OOTB components (TOC and any others) from user code in one's own usercontrol? If there is no way to get an object reference, perhaps an interim step would be to understand why making the TOC tabItem visible (and yes, selecting its index in tabControl) does not show the TOC unless using the OOTB button to first open the control.

Any help on this is appreciated.

thanks,
Danny
0 Kudos
4 Replies
PietaSwanepoel2
Frequent Contributor
0 Kudos
DannyVenier
Deactivated User
Thanks Pieta,

Your earlier post on expanding the TOC on load was useful to me but my real objective is to get access to the component (TOC) itself.  There are only limited things that can be done by accessing the layout containers that hold the components, rather than the components themselves.  In the case of showing and hiding the TOC, your suggestions should be enough to accomplish this, but as I mentioned in my post, making the tab container visible or invisible and playing the storyboard has some quirks, for some reason, until after the control has been opened/initialized (not sure which) by the existing command button.

I would think it is a general requirement by anyone extending or making a custom viewer, that they can reference the important components of the viewer (TOC) so that they can, for example, extend the component or have other components interact in a rich way with them.  I was hoping for an answer like "the TOC object name for the default viewer is.....", although by breakpointing, the object inthe TOC tab container has a blank name "" so it isn't so easy.

If you have some insight as to why my attempts to make the tab container holding the TOC visible, and playing the storyboard that is contained in the layer....does not work, that would be great.  Short term, just having visibility control of TOC would be good.

thanks.
0 Kudos
PietaSwanepoel2
Frequent Contributor
Danny,

would a possible alternative be to add the layers manually (add-in or behavior doing it). That why you have more control over the layers as you add them. You therefor have a blank application (only base layer) and ass and reference the layer programmatically.
Or you could write your own legend control and have more control over the look and feel of it

Example of legend code:
  <Border x:Name="legendBorder" Background="#CC345BA9" Margin="0,60,8,0" Padding="4,0,4,4" CornerRadius="10" HorizontalAlignment="Right" VerticalAlignment="Top" 
    d:LayoutOverrides="Height" BorderThickness="1" BorderBrush="Black" Visibility="Collapsed" >
   <Border.Effect>
    <DropShadowEffect/>
   </Border.Effect>
   <i:Interaction.Behaviors>
    <ei:MouseDragElementBehavior/>
   </i:Interaction.Behaviors>
   <StackPanel>
    <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
     <sdk:Label Content="Legend" FontWeight="Bold" FontSize="16" Margin="0,0,415,0" HorizontalAlignment="Left" Foreground="#FFF3FAFE"/>
     <Button x:Name="btnCloseLegend" Content="Button" Click="btnCloseLegend_Click" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,7,0" Style="{StaticResource ImageButton_Style}" Padding="0"/>
    </StackPanel>
    <Border BorderBrush="Black" BorderThickness="1" CornerRadius="10" Background="White" Padding="8">
     <esri:Legend x:Name="legend"
        Map="{Binding ElementName=map1}"  
        LayerItemsMode="Tree" 
        ShowOnlyVisibleLayers="False"
        MinHeight="400" MaxHeight="400" MinWidth="506" MaxWidth="506"
        Refreshed="Legend_Refreshed">
      <!-- Data template for map layers. Map layers can be services with sublayers or a layer within a service.-->
      <esri:Legend.MapLayerTemplate>
       <DataTemplate>
        <StackPanel Orientation="Horizontal">
         <CheckBox Content="{Binding Label}"
          IsChecked="{Binding IsEnabled, Mode=TwoWay}"
          IsEnabled="{Binding IsInScaleRange}" >
         </CheckBox>
         <Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="50" />
        </StackPanel>
       </DataTemplate>
      </esri:Legend.MapLayerTemplate>
      <!-- Data template for sublayers within a map layer-->
      <esri:Legend.LayerTemplate>
       <DataTemplate>
        <CheckBox Content="{Binding Label}"
         IsChecked="{Binding IsEnabled, Mode=TwoWay}"
         IsEnabled="{Binding IsInScaleRange}" >
        </CheckBox>
       </DataTemplate>
      </esri:Legend.LayerTemplate>
     </esri:Legend>
    </Border>
   </StackPanel>
  </Border>
0 Kudos
DannyVenier
Deactivated User
Hi Pieta,

Yes, your suggestion is possible and quite appealing since extending an OOTB component with no source is not feasible.

I considered writing a custom TOC but thought it might be daunting in short term, but your code sample is very helpful in convincing me to take that approach.

thanks for all your help and followup on this topic.

Regards,
Danny
0 Kudos