将样式应用于所有 TreeViewItem
您好,我遇到的问题是我有多个 TreeView 控件,每个 TreeView 都有自己的 TreeViewItem 样式, 设置它
TreeView ItemContainerStyle="{StaticResource Style1}"
只会设置根元素而不是所有子元素,如何将样式应用于 TreeView 中的所有子元素
Hi The problem am having is that I have multiple TreeView control and each TreeView has its own TreeViewItem styles,
setting it
TreeView ItemContainerStyle="{StaticResource Style1}"
will only set the root element NOT all the child elements, How to apply a style to all the child elements in a TreeView
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有多种方法可以实现此目的:
您可以将样式设置为所有 TreeViewItems 的默认样式:
不同之处在于您不设置 x:Key 属性,但设置 TargetType 属性。在这种情况下,您不需要在 TreeView 上设置 ItemContainerStyle。
You could also set your style as the default style for all TreeViewItems, but only within your TreeView:
在这种情况下,您也不需要在 TreeView 上设置 ItemContainerStyle。
您还可以按如下方式更改样式。
在这种情况下,您仍然需要在 TreeView 上设置 ItemContainerStyle。
There are several ways to accomplish this:
You could make your style the default for all TreeViewItems:
The difference is that you do not set the x:Key attribute, but you do set the TargetType attribute. You do not need to set the ItemContainerStyle on your TreeView in this case.
You could also set your style as the default style for all TreeViewItems, but only within your TreeView:
In this case you also do not need to set the ItemContainerStyle on your TreeView.
You could also alter your style as follows
In this case you'd still have to set the ItemContainerStyle on your TreeView.