<TreeView Grid.Row="0" Grid.Column="0" Name="StagesTreeView" Margin="5">
<TreeView.Resources>
<Style TargetType="{x:Type TreeViewItem}">
<!-- <Setter Property="?????"> WHAT SHOULD BE HERE?
<Setter.Value>
</Setter.Value>
</Setter> -->
</Style>
</TreeView.Resources>
</TreeView>
告诉我吧。一些简单的例子
UPD:哦......我想我需要一个ControlTemplate,但我仍然不知道如何制作它 UPD2:天哪,我正在深入研究这个问题,我感到很困惑。我应该在这里的某处使用RelativeSource标记扩展吗?有人帮帮我!UPD3:现在它不像TreeBox那样工作 - 我无法展开\折叠项目,虽然我稍微向前移动 - 我可以看到复选框。
<TreeView Grid.Row="0" Grid.Column="0" Name="StagesTreeView" Margin="5">
<TreeView.Resources>
<Style x:Key="{x:Type TreeViewItem}" TargetType="TreeViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid Margin="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<CheckBox IsChecked="{Binding Path=IsActive}"/>
<TextBlock Text="{Binding Path=Alias.UserName}"/>
</StackPanel>
<ItemsPresenter Grid.Row="1"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TreeView.Resources>
</TreeView>
答案 0 :(得分:3)
这样的事情:
<TreeView Grid.Row="0" Grid.Column="0" Name="StagesTreeView" Margin="5">
<TreeView.Resources>
<Style TargetType="TreeViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeViewItem">
<StackPanel Orientation="Horizontal">
<CheckBox Margin="2" Name="checkBox1"/>
<Border Padding="2">
<ContentPresenter Name="PART_header" ContentSource="Header"/>
</Border>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TreeView.Resources>
</TreeView>
答案 1 :(得分:2)
您可能会觉得这很有用:Working with Checkboxes in the WPF TreeView