我需要将样式应用于堆栈面板中的不同控件。它们都有不同的类型,即 TreeView、Listview、ComboBox 等。 有没有办法可以在 StackPanel 级别应用适用于这些控件的样式。 我不想将样式单独应用于这些控件。 有什么办法可以实现这一点吗?
谢谢..
最佳答案
您可以通过在 StackPanel 资源中声明样式来做到这一点。您必须在没有键的情况下声明每个样式,以便它们自动应用于 StackPanel 中的每个目标控件。
<StackPanel>
<StackPanel.Resources>
<!-- Styles declared here will be scoped to the content of the stackpanel -->
<!-- This is the example of style declared without a key, it will be applied to every TreeView. Of course you'll have to add Setters etc -->
<Style TargetType="TreeView">
</Style>
</StackPanel.Resources>
<!-- Content -->
<!-- This treeview will have the style declared within the StackPanel Resources applied to it-->
<TreeView />
</StackPanel>
关于c# - WPF-如何将样式应用于面板中的多个控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6212793/