当我通过 DataContext 设置 treeviewitem 的标题时,它会添加一些可单击的填充像素,然后将文本放置为不可单击。我将张贴图片;蓝色:可点击,红色:不可点击。
存储数据的类:
public class TagClass
{
public string TagClassMagic { get; set; }
public ITagClass RawClass { get; set; }
public List<TagEntry> TagEntries = new List<TagEntry>();
public IList Children
{
get
{
return new CompositeCollection()
{
new CollectionContainer() { Collection = TagEntries }
};
}
}
}
public class TagEntry
{
public string TagFileName { get; set; }
public ITagEntry RawTag { get; set; }
}
用于显示数据的 XAML:
<TreeView x:Name="tvTagList" Margin="15, 40, 15, 50" ItemsSource="{Binding}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="{x:Null}" BorderBrush="{DynamicResource ExtryzeAccentBrushSecondary}" BorderThickness="2" ScrollViewer.CanContentScroll="True" Foreground="White">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type DataBind:TagClass}" ItemsSource="{Binding Children}" >
<TreeViewItem Header="{Binding TagClassMagic}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type DataBind:TagEntry}" >
<TreeViewItem Header="{Binding TagFileName}" />
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>