Example of Legend with Templates in a Style

716
7
09-06-2011 02:09 PM
KirkKuykendall
Occasional Contributor III
Hi -

I'm using the Legend from this sample:
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#LegendWithTemplates

And would like to put the templates into a style.  Is there a sample somewhere that shows how to do this?

Thanks!
0 Kudos
7 Replies
DominiqueBroux
Esri Frequent Contributor
You can put the legend templates in a style by code like:
 
<Style x:Key="legendStyleName" TargetType="esri:Legend">
  <Setter Property="LayerItemsMode" Value="Tree" />
  <Setter Property="MapLayerTemplate">
   <Setter.Value>
    <DataTemplate>...........


There are a lot of style samples here : http://www.arcgis.com/home/item.html?id=c673bf3e983b418495eeb0f45bb44c68
0 Kudos
KirkKuykendall
Occasional Contributor III
Thanks, this helps a lot.

I'm also wanting to style the appearance of the little triangles used to expand/collapse group layers.

Notice how the black background on this sample makes it impossible to see the black triangles next to group layers that are expanded.  After the background to orange, I can see them (see attached).  How could I just change the color for the triangle when it's in an expanded state?
0 Kudos
DominiqueBroux
Esri Frequent Contributor

How could I just change the color for the triangle when it's in an expanded state?

The legend control is based on a treeview that you can customize.
To change the expander button, you have to change the TreeViewItem style.

The easiest way is with BLEND:
- Right-Click your Legend control
[INDENT]. Edit Template
. Edit a Copy...
[/INDENT]- Right Click the TreeViewExtended of the created template
[INDENT]. Edit Additional Templates
. ItemContainerStyle
. Edit a Copy...
[/INDENT]- Right Click the Expander button (toogle button)
[INDENT]. Edit Template
. Edit Current
[/INDENT]- Change the UncheckedVisual and CheckedVisual element as you want

By googling you might also find sample of expander button. Example : http://stackoverflow.com/questions/3444375/custom-expand-collapse-symbols-in-silverlight-treeview-us...
0 Kudos
KirkKuykendall
Occasional Contributor III
Ahh, thanks, I should have known better than try to deal visually with this code in Visual Studio.

I'm not sure if this is a bug, but if I run the original demo app without any changes, and go to the TOC template, I'm unable to toggle on and off different sub layers (like Hydrants).  See attached.

Is this an error in the style somewhere?

0 Kudos
KirkKuykendall
Occasional Contributor III
I think this is a bug in the setter for LayerItemViewModel.IsEnabled, I changed the demo code:

<!--<CheckBox IsChecked="{Binding IsEnabled, Mode=TwoWay}" IsEnabled="{Binding IsInScaleRange}" VerticalAlignment="Center"/>-->
            <!--<TextBlock Text="{Binding Label}" VerticalAlignment="Center"  />-->
            <Button VerticalAlignment="Center">
                <TextBlock Text="{Binding Label}" />
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click" >
                        <local:ShowLayerInfoAction/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>


And in the ShowLayerInfoAction, debug always prints true before and after:
protected override void Invoke(object parameter)
{
    try
    {
        var livm = this.AssociatedObject.DataContext as LayerItemViewModel;
        var dynLayer = livm.Layer as ArcGISDynamicMapServiceLayer;
        Debug.WriteLine("IsEnable before " + livm.IsEnabled.ToString());
        livm.IsEnabled = !livm.IsEnabled;
        Debug.WriteLine("IsEnable after " + livm.IsEnabled.ToString());
        //string url = String.Format("{0}/{1}",dynLayer.Url,livm.SubLayerID);
        //HtmlPage.Window.Navigate(new Uri(url), "_blank");
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.Message);
    }
}
0 Kudos
KirkKuykendall
Occasional Contributor III
OK, never mind, I now see this isn't expected to work for single fused cache layers.
http://forums.arcgis.com/threads/31873-Unusual-Legend-Behavior-for-Grouping?p=118901&viewfull=1#post...

Seems like Esri should choose a different mapservice for this demo app, instead of this one ...
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/WaterTemplate/WaterDistributionNetwork/Ma...
0 Kudos
DominiqueBroux
Esri Frequent Contributor

OK, never mind, I now see this isn't expected to work for single fused cache layers.


Right. From AGS version 10, the map services have been optimized to use the cache when this one exists. The counterpart is that it's no more possible to change the sublayer visibilities or set the layer definitions.


Seems like Esri should choose a different mapservice for this demo app, instead of this one ...

Right. You'll try to change that.
When the demo has been created, the server was in 9.3.1 and it was possible to change the sublayer visibilities. But the server has been updated meanwhile.
0 Kudos