C# WPF TreeView,在图标左侧选择图标移除
我有一个WPF树视图,我想删除图标左侧的蓝色“选定”悬停。 我希望你明白我想要什么:D 这是问题的图片 树视图由代码隐藏填充,我以编程方式构建该项 TreeViewItem.Header XAML如下所示:C# WPF TreeView,在图标左侧选择图标移除,c#,wpf,xaml,treeview,C#,Wpf,Xaml,Treeview,我有一个WPF树视图,我想删除图标左侧的蓝色“选定”悬停。 我希望你明白我想要什么:D 这是问题的图片 树视图由代码隐藏填充,我以编程方式构建该项 TreeViewItem.Header XAML如下所示: <StackPanel Orientation="Horizontal" ...> <Image ... /> <TextBlock .../> </StackPanel> 这就像是一个解决办法,不是一个好的解决方案: &l
<StackPanel Orientation="Horizontal" ...>
<Image ... />
<TextBlock .../>
</StackPanel>
这就像是一个解决办法,不是一个好的解决方案:
<StackPanel Orientation="Horizontal" Margin="-1,0,0,0">
<Image Source="/Images/yourImage.jpg" Height="30" Width="30"/>
<TextBlock Text="Hey"/>
</StackPanel>
及其层次结构数据模板
:
<TreeView ItemsSource="{Binding Leafs}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type vm:LeafViewModel}" ItemsSource="{Binding Children}">
<ContentControl Content="{Binding }">
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="ContentTemplate" Value="{StaticResource DefaultTemplate}"/>
</Style>
</ContentControl.Style>
</ContentControl>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
<HierarchicalDataTemplate x:Key="DefaultTemplate" DataType="{x:Type vm:LeafViewModel}" ItemsSource="{Binding Children}">
<Border Tag="{Binding DataContext, RelativeSource={RelativeSource Self}}" Background="Transparent">
<StackPanel Orientation="Horizontal">
<Label VerticalAlignment="Center" FontFamily="WingDings" Content="1"/>
<CheckBox IsChecked="{Binding IsCheckedFoo}"/>
<TextBlock Name="leafTxtBox" Text="{Binding LeafName}" Tag="{Binding DataContext, RelativeSource={RelativeSource Self}}" Background="Transparent"/>
</StackPanel>
</Border>
</HierarchicalDataTemplate>
关于如何使用TreeView的最佳文章将项目包装到TreeView项目容器中。TreeViewItem具有填充
1,0,0,0
,可以通过样式删除
<TreeView.Resources>
<Style TargetType="TreeViewItem">
<Setter Property="Padding" Value="0"/>
</Style>
</TreeView.Resources>
通常有4个笔刷与此相对应,并由TreeViewItem的默认模板使用 关键点: HighlightBrushKey-具有焦点的背景 HighlightTextBrushKey-具有焦点的前景 InactiveSelectionHighlightBrushKey-背景无焦点 InactiveSelectionHighlightTextBrushKey-前景无焦点 只要在您认为合适的情况下覆盖它们,对于您的需求,类似这样的操作就可以了:
<TreeView>
<TreeView.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}"
Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"
Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}"
Color="Black" />
</TreeView.Resources>
</TreeView>
Im不太适合MVVM和数据绑定。你的第一个例子对我来说是正确的。。。。我知道,我必须学习xaml:D