在 XAML 中使用绑定设置样式
我需要根据 Silverlight 中的某些配置值设置给定控件的 Style
。我希望能够从两种可用样式(静态资源)中为控件选择Style
。我试图做类似的事情:
<TextBox Style="{Binding ABC}"/>
不幸的是
public string ABC
{
get {return "{StaticResource MyStyle}";}
}
,这不起作用。
你有什么想法吗?
提前致谢!
干杯
I need to set a Style
of a given control according to some configuration value in Silverlight. I would like to have a possibility of choosing a Style
for a control from two available styles (static resources). I was trying to do something like:
<TextBox Style="{Binding ABC}"/>
where
public string ABC
{
get {return "{StaticResource MyStyle}";}
}
Unfortunately, that does not work.
Do you have any ideas?
Thanks in advance!
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你很接近。不过,您需要将
Style
属性绑定到Style
类型的属性(不是表示静态资源查找的字符串)。您有两种样式存储选项,这将决定属性的外观。将样式放入页面资源或应用程序资源中,然后您的 ABC 属性将类似于以下内容之一:
其中
_myStyle
是样式的x:Key 值资源字典中的
属性。You are close. You need to be binding the
Style
property to a property of typeStyle
though (not a string representing a static resource lookup).You have two options for storage of the style and this will determine what the property looks like. Either put the style in the pages resources or in the App resources, and then you ABC property will look like one of the following:
Where
_myStyle
is the value the style has for itsx:Key
property in the resource dictionary.