1

次の機能を備えた TreeView を構築したいと思います。

  1. 最初のレベルには、左側ではなく右側にエキスパンダー ボタンが必要です。
  2. デフォルトの TreeViewItem と同様に、すべてのサブレベルの左側にエキスパンダー ボタンが必要です。
  3. 展開/折りたたみは、展開コントロールと同じようにアニメーション化する必要があります

私は DataTemplate と HierarchicalDataTemplate をいじっていましたが、Expander-Button はテンプレートの一部ではないようで、常にテンプレートに追加され、常に左側にあります。項目レベルに応じて Expander-Button を配置するにはどうすればよいですか?

4

1 に答える 1

1

ToggleButton 列を変更して、 TreeViewItem ControlTemplateをカスタマイズする必要があります。次に、スタイル内の DataTrigger を使用してコントロール テンプレートを変更するだけです。

<Style x:Key="{x:Type TreeViewItem}" TargetType="{x:Type TreeViewItem}">
  <!-- snip -->
  <ControlTemplate TargetType="{x:Type TreeViewItem}">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition MinWidth="19" Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
      </Grid.RowDefinitions>
      <ToggleButton Grid.Column="1" x:Name="Expander"
              Style="{StaticResource ExpandCollapseToggleStyle}"
              IsChecked="{Binding Path=IsExpanded,
                          RelativeSource={RelativeSource TemplatedParent}}"
              ClickMode="Press"/>
      <Border Name="Bd"
          Grid.Column="0"
          Background="{TemplateBinding Background}"
          BorderBrush="{TemplateBinding BorderBrush}"
          BorderThickness="{TemplateBinding BorderThickness}"
          Padding="{TemplateBinding Padding}">
        <ContentPresenter x:Name="PART_Header"
                  ContentSource="Header"
                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/>
      </Border>
      <ItemsPresenter x:Name="ItemsHost"
              Grid.Row="1"
              Grid.Column="1"
              Grid.ColumnSpan="2"/>
    </Grid>
    <ControlTemplate.Triggers>
      <!-- snip -->
    </ControlTemplate.Triggers>
  </ControlTemplate>
</Style>
于 2013-02-15T07:40:20.597 に答える