gpt4 book ai didi

c# - WPF-如何将样式应用于面板中的多个控件

转载 作者:行者123 更新时间:2023-11-30 22:38:09 24 4
gpt4 key购买 nike

我需要将样式应用于堆栈面板中的不同控件。它们都是不同的类型,即 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com