简体   繁体   English

如何在WPF XAML中的不同样式之间进行选择

[英]How to choose between different styles in WPF XAML

I am creating a popup dialog using microsoft's WPF. 我正在使用Microsoft的WPF创建一个弹出对话框。

The thing is that this popup must support two or more different styles, for instance, depending on how it is called the popup must have a red background and white text in the foreground, or it must have a white background and gray text in the foreground. 问题是该弹出窗口必须支持两种或更多种不同的样式,例如,取决于如何将其称为弹出窗口。前台必须具有红色背景和白色文本,或者前台必须具有白色背景和灰色文本。

What I would like to do is create as many styles as necessary in my xaml file and just choose each of them depending on how the popup was created, therefore I would like to know if it is possible to create something like this (kind of a dynamically applied style) inside the .xaml file, or if it is better to just do this programatically in the code behind. 我想做的是在xaml文件中创建尽可能多的样式,然后根据弹出窗口的创建方式选择每种样式,因此,我想知道是否可以创建这样的样式(有点像动态应用样式),或者最好在后面的代码中以编程方式执行此操作。

Also please note that I am using the Visual Studio 2010 with the .NET Framework 4.0. 还请注意,我将Visual Studio 2010与.NET Framework 4.0一起使用。

Thanks, 谢谢,

Felipe 费利佩

我将定义一个命名样式的枚举,然后使用DataTriggers从包装边框在控件上设置样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM