你能帮我吗?我需要每个项目都带有CheckBox的TreeView。我无法得到它,我开始像这样,并且看起来像绝对错误的方式:WPF TreeView与自定义风格
<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:哦......我想我需要一个控件模板,但我仍然不知道如何使它
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>
看起来非常适合我。等一下,我要仔细检查一下。谢谢! – Agzam 2009-07-16 14:58:13
我不能整理出来。我是一个糟糕的程序员。这些WPF事情现在非常困难,也让我感到纠结。 – Agzam 2009-07-16 18:18:02