App.xaml Application.Resources 中的 WP7 绑定
在 App.xaml
中,
我有:
<Color x:Key="ColorMain">#FF1F879C</Color>
<SolidColorBrush x:Key="ColorBrushMain" Color="{StaticResource ColorMain}"/>
然后我有许多使用此画笔和颜色的模板。这些模板在整个应用程序中使用。
我需要有能力改变颜色来改变整个应用程序的皮肤。 我需要类似:
<SolidColorBrush x:Key="ColorBrushMain" Color="{Binding ColorMain}"/>
并在代码中类似:
public string ColorMain {
get {
return ..... ; // "#FF803200";
}
}
但它不起作用。请帮忙。
UPD:abhinav 是对的,它必须是一种颜色
public Color ColorMain {
get {
return ..... ; // return Color.FromArgb(0xFF, 0x80, 0x32, 0x00);
}
}
,但这还不够,它没有约束力。我认为它必须与普通页面上的 DataContext
到 ViewModel
一样,但是什么呢?
In App.xaml <Application.Resources>
I have:
<Color x:Key="ColorMain">#FF1F879C</Color>
<SolidColorBrush x:Key="ColorBrushMain" Color="{StaticResource ColorMain}"/>
then I have many templates which are using this brush and color. These templates are used all over the application.
I need to have an ability to change the color to change the skin of whole application.
I need something like:
<SolidColorBrush x:Key="ColorBrushMain" Color="{Binding ColorMain}"/>
and in code something like:
public string ColorMain {
get {
return ..... ; // "#FF803200";
}
}
But it doesn't work. Please help.
UPD: abhinav is right it must be a color
public Color ColorMain {
get {
return ..... ; // return Color.FromArgb(0xFF, 0x80, 0x32, 0x00);
}
}
but this is not enough, it's not binding. I assume that it must be something as on normal page with DataContext
to ViewModel
, but what?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您要绑定到存储 Color 的属性,并且要在运行时更改并期望它更新,那么您是否也需要实现 INotifyPropertyChanged ?例如:
所以:如果您希望在运行时更改颜色,请使用绑定并实现 INotifyPropertyChanged - 如果颜色不会在运行时更改,那么您已经拥有的应该没问题。
If you're binding to a property that stores the Color and you're going to change at runtime and expect it to update, don't you need to be implementing INotifyPropertyChanged as well? For example:
So: if you're expecting to change the color at runtime, use binding and implement INotifyPropertyChanged - if the colour isn't going to change at runtime, what you've already got should be fine.
您正在将颜色属性绑定到字符串对象。
虽然我从未尝试过,但我很确定它不会起作用。
也许课程的文档会有所帮助。 查看此链接。
您是否尝试使用颜色类别呢?
You're binding a color property to a string object.
Although I've never tried it, I'm quite sure that it will not work.
Maybe the documentation of the class will help. See this link.
Did you try using the color class instead?