在xaml中:
<TreeView Name="asd" Margin="575,26,265,350">
<TreeView.Resources>
<Style x:Key="TreeViewItemStyle" TargetType="TreeViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeViewItem">
<StackPanel Orientation="Horizontal">
<CheckBox Margin="1" Name="checkBox1" HorizontalAlignment="Right" VerticalAlignment="Center" Content="{TemplateBinding TreeViewItem.Header}" Checked="checkBox1_Checked" Unchecked="checkBox1_Unchecked"></CheckBox>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TreeView.Resources>
<TreeViewItem Header="a">
<TreeViewItem Header="a1">
<TreeViewItem Header="a11" Style="{DynamicResource TreeViewItemStyle}"></TreeViewItem>
</TreeViewItem>
<TreeViewItem Header="a2" Style="{DynamicResource TreeViewItemStyle}"></TreeViewItem>
<TreeViewItem Header="a3" Style="{DynamicResource TreeViewItemStyle}"></TreeViewItem>
</TreeViewItem>
<TreeViewItem Header="b">
<TreeViewItem Header="b1" IsEnabled="False" Style="{DynamicResource TreeViewItemStyle}"></TreeViewItem>
</TreeViewItem>
<TreeViewItem Header="c" Style="{DynamicResource TreeViewItemStyle}"></TreeViewItem>
</TreeView>
运行后,前两个有分支,第三个item是一个checkbox形式的。我对于控件的样式理解的不是很好。我还想实现的是:前两个item左边的加号标志和第三个item左边的方框对齐。不知道这样的效果是否可以实现,那控件的样式该如何写呢?请各位高手帮帮忙,谢谢!