Problem styling Legend control

774
3
11-10-2011 08:49 PM
Labels (1)
linusang
New Contributor II
Hi, I would like to use my own TreeView style in the Legend control, however I can't seems to render the items at all, only the MapLayerTemplate is rendered. If i use the default style(without specifying Template property), it works fine.

Here is the xaml for my Legend.Template property. (I got most of the xaml code from Blend's "Edit a Copy" function)

<esri:Legend.Template>
                <ControlTemplate TargetType="{x:Type esri:Legend}">

                    <TreeView BorderBrush="{TemplateBinding BorderBrush}" 
      BorderThickness="{TemplateBinding BorderThickness}" 
      Background="{TemplateBinding Background}" 
      Foreground="{TemplateBinding Foreground}" 
      HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
      Padding="{TemplateBinding Padding}" 
      VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                        ItemsSource="{TemplateBinding LayerItemsSource}">
                        <TreeView.ItemTemplate>
                            <HierarchicalDataTemplate AlternationCount="0" 
                                                          ItemBindingGroup="{x:Null}" 
                                                          ItemTemplate="{x:Null}" 
                                                          ItemContainerStyleSelector="{x:Null}" 
                                                          ItemStringFormat="{x:Null}" 
                                                          ItemsSource="{Binding LayerItemsSource}" 
                                                          ItemContainerStyle="{x:Null}" 
                                                          ItemTemplateSelector="{x:Null}">
                                <ContentPresenter ContentTemplate="{Binding Template}" Content="{Binding}"/>
                            </HierarchicalDataTemplate>
                        </TreeView.ItemTemplate>
                        <TreeView.ItemContainerStyle>
                            <Style TargetType="{x:Type TreeViewItem}">
                                <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
                                <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
                            </Style>
                        </TreeView.ItemContainerStyle>
                        <TreeView.Template>
                            <ControlTemplate TargetType="{x:Type TreeView}">
                                <s:SurfaceScrollViewer Background="{TemplateBinding Background}"
                                                           BorderBrush="{TemplateBinding BorderBrush}"
                                                           BorderThickness="{TemplateBinding BorderThickness}"
                                                           Foreground="{TemplateBinding Foreground}"
                                                           Style="{StaticResource VerticalSurfaceScrollViewerStyle}">
                                    <ItemsPresenter/>
                                </s:SurfaceScrollViewer>
                            </ControlTemplate>
                        </TreeView.Template>
                    </TreeView>
                </ControlTemplate>
            </esri:Legend.Template>
0 Kudos
3 Replies
linusang
New Contributor II
Managed to solve the problem...

HierarchicalDataTemplate should just define like the following (removing the ItemBindingGroup, ItemContainerStyleSelector, etc....):

<HierarchicalDataTemplate ItemsSource="{Binding LayerItemsSource}">
     <ContentPresenter ContentTemplate="{Binding Template}" Content="{Binding}"/>
</HierarchicalDataTemplate>


hope it is useful for those having the same problem....
0 Kudos
BKuiper
Occasional Contributor III
I'm experiencing the same problem but the proposed solution won't work for me. I'm using the ArcGIS Runtime 10.1 BETA 2 WPF SDK. I would like to restyle the Legend (main) Template and perhaps restyle the Treeview template within that.

Anybody has an example that works? Thank you!
0 Kudos
DominiqueBroux
Esri Frequent Contributor
The default legend template should be a good starting point:
 
<ControlTemplate TargetType="esriToolkit:Legend">
    <TreeView     ItemsSource="{TemplateBinding LayerItemsSource}"                            
                                Background="{TemplateBinding Background}"
                                Foreground="{TemplateBinding Foreground}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"      
                                Padding="{TemplateBinding Padding}"
                                HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
        >
        <TreeView.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding LayerItemsSource}" >
                <ContentPresenter TextElement.Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type TreeView}} }" Content="{Binding}" ContentTemplate="{Binding Template}" />
            </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>
        <TreeView.ItemContainerStyle>
            <Style TargetType="TreeViewItem">
                <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
                <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
            </Style>
        </TreeView.ItemContainerStyle>
    </TreeView>
</ControlTemplate>


From that, there are lot of customization possibilities. Let us know what kind of issue you run into.
0 Kudos