icube

Problem styling Legend control

Discussion created by icube on Nov 10, 2011
Latest reply on Dec 26, 2011 by dbroux-esristaff
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>

Outcomes