更改分层 TreeView 中的突出显示颜色
我有一个带有 HierarchicalDataTemplate 的 TreeView。
<HierarchicalDataTemplate x:Key="treeViewItemTemplate" ItemsSource="{Binding GetChildren}">
<DockPanel Margin="0,8,8,0">
<Image Source="{Binding GetImage}" Width="16" Height="16" />
<local:MonitorTriStateCheckBox Margin="4,0,0,0" IsChecked="{Binding IsChecked}" Click="CheckBox_Clicked" Tag="{Binding UniqueKey}" Style="{DynamicResource CheckBox}"></local:MonitorTriStateCheckBox>
<TextBlock Margin="4,0,0,0" Text="{Binding Name}" Style="{DynamicResource TextBlock}">
</TextBlock>
</DockPanel>
<HierarchicalDataTemplate.Triggers>
<Trigger Property="TreeViewItem.IsSelected" Value="True">
<Setter Property="TreeViewItem.Background" Value="Orange" />
</Trigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
正如您在代码中看到的,我设置了TreeViewItem的is selected触发器,但这没有效果。我也尝试过这个:
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="Visibility" Value="{Binding IsVisible, Mode=TwoWay}" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Orange" />
</Trigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
但这也没有效果。
有谁知道该怎么做,改变 TreeViewItem 的突出显示颜色?
I have got a TreeView with a HierarchicalDataTemplate.
<HierarchicalDataTemplate x:Key="treeViewItemTemplate" ItemsSource="{Binding GetChildren}">
<DockPanel Margin="0,8,8,0">
<Image Source="{Binding GetImage}" Width="16" Height="16" />
<local:MonitorTriStateCheckBox Margin="4,0,0,0" IsChecked="{Binding IsChecked}" Click="CheckBox_Clicked" Tag="{Binding UniqueKey}" Style="{DynamicResource CheckBox}"></local:MonitorTriStateCheckBox>
<TextBlock Margin="4,0,0,0" Text="{Binding Name}" Style="{DynamicResource TextBlock}">
</TextBlock>
</DockPanel>
<HierarchicalDataTemplate.Triggers>
<Trigger Property="TreeViewItem.IsSelected" Value="True">
<Setter Property="TreeViewItem.Background" Value="Orange" />
</Trigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
As you can see in the code, i set the is selected Trigger of the TreeViewItem, but this has no effect. I alos tried this:
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="Visibility" Value="{Binding IsVisible, Mode=TwoWay}" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Orange" />
</Trigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
But that had no effect either.
Has anyone got an idea what to do, to change the hightlight color of a TreeViewItem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个...
Try this...