对于 WPF TreeView,如何在设置 TreeView.ItemContainerStyle 的同时使用主题
我在 XAML 中使用它从基于 Josh Smith 的示例代码 此处的视图模型加载树视图子级:
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
</Style>
</TreeView.ItemContainerStyle>
这会导致我用于 TreeViewItem 的主题被忽略。它将所选项目的文本设为黑色,背景设为深蓝色,因此难以阅读。有没有办法同时使用主题和上面的代码?
I use this in XAML to load the treeview children from a view model based on Josh Smith's sample code here:
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
</Style>
</TreeView.ItemContainerStyle>
This causes the theme I'm using for TreeViewItem to be ignored. It makes the selected item text black and the background darkblue so it's hard to read. Is there a way to use both the theme and the code above at the same time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试设置
BaseOn
到{StaticResource {x:Type TreeViewItem}}
。这会将 TreeViewItems 的默认样式(由主题提供)作为样式的基础。
Try setting
BasedOn
to{StaticResource {x:Type TreeViewItem}}
.This will take the default style for
TreeViewItems
(which is provided by the theme) as the base for your style.只是格式化的代码:
Just the code formated: