views:

17

answers:

0

Hi there,

I am in the process of customizing a treeview contro, well its actually the treeview items. My understanding of a hierarchical control is more or less teh same as a non-hierarchical control like a listbox. So maybe if I explaing that you can tell me where im going wrong. When customizing a non-hierarchical data control I basicly use the ItemContainerStyle and ItemTemplate. For defining the container a ControlTemplate is used and somewhere inside that a ContentPresenter is placed. In turn this ContentPresenter represents the actually item which is defined in the ItemTemplate and is of the type DataTemplate. Nice an easy.

So with the TreeView I thought it would be the same just with a few changes. These changes being that the ItemContainerStyle (template) in addition ot a ContentPresenter needs an ItemsPresenter. The second change is the ItemTemplate, instead of a DataTemplate we need a HierarchicalDataTemplate and have its ItemsSource binded to the treeviewItems child collection. Inside the HierarchicalDataTemplate I place a panel with textblock, border etc

The problem is that the ContentPresenter does not display. Everything inside the TreeViewItem.Template is fine but the damn content is no where to be seen. It is no doubt me that has misunderstod somthing with the treeview control but I just can't see what. Here is a the code that I have been trying with. For simplicity I have left out the trigger logic to expand/collapse the tree this this just renders a folly expanded tree, but without the content showing.

<Style x:Key="testStyle" TargetType="TreeView">
  <Setter Property="ItemContainerStyle">
    <Setter.Value>
      <Style TargetType="TreeViewItem">
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate>
              <Grid Background="Pink" VerticalAlignment="Center">
                <Grid.RowDefinitions>
                  <RowDefinition MinHeight="20" Height="Auto" />
                  <RowDefinition MinHeight="5" Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition MinWidth="20" Width="Auto"/>
                  <ColumnDefinition MinWidth="20" Width="Auto"/>
                  <ColumnDefinition MinWidth="50" Width="*"/>
                </Grid.ColumnDefinitions>
                <Rectangle Width="15" Height="15" Fill="RoyalBlue" Grid.Column="0" Grid.Row="0" />
                <ItemsPresenter Grid.Column="1" Grid.Row="1" />
                <ContentPresenter x:Name="PART_Header" Grid.Column="1" Grid.Row="0" />
              </Grid>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
    </Setter.Value>
  </Setter>
  <Setter Property="ItemTemplate">
    <Setter.Value>
      <HierarchicalDataTemplate ItemsSource="{Binding Children}" DataType="SettingViewModel">
        <TextBlock Text="some header text" />
      </HierarchicalDataTemplate>
    </Setter.Value>
  </Setter>
</Style>

Thanks in advance,

Regards

-Christian