WPF静态绑定问题 [英] wpf static binding question
本文介绍了WPF静态绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
玉家伙,
我有一个严重的问题与此有关。
I have a serious problem with this.
我有静电性能提供了一些颜色为十六进制字符串一个静态类:
I have a static class with static properties providing some colors as a hex string:
namespace com.myCom.Views
{
public static class MyColorTable
{
private const string _Hex0 = "#FFFFFFFF";
private const string _Hex1 = "#FFE5E5E5";
public static String Hex0
{
get { return _Hex0; }
}
public static String Hex1
{
get { return _Hex1; }
}
}
}
现在,我想这些颜色绑定到通过XAML一个用户控件,就像这样:
Now, I want to bind these colors to a UserControl via XAML, like this:
<UserControl x:Class="com.testing.MyTestClass"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="53" Width="800"
FocusVisualStyle="{x:Null}">
<Grid x:Name="MyGrid"
Focusable="false"
FocusManager.IsFocusScope="True"
Background="{Binding Soure={x:Static MyColorTable}, Path=Hex1}"
Margin="0,0,0,0"
FocusVisualStyle="{x:Null}"
/>>
我知道,这是不行的,所以我的问题是,我怎么做是正确的?我并不需要双向绑定或任何的PropertyChanged事件,因为一旦应用程序启动时,颜色不会被更新。
I know that this does not work, so my question is, how am I doing it right? I don't need two-way-binding or any PropertyChanged events, since the colors will not be updated once the app is started.
推荐答案
明白了:
<UserControl x:Class="com.testing.MyTestClass"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:colors="clr-namespace:com.myCom.Views;assembly=com.myCom"
Height="53" Width="800"
FocusVisualStyle="{x:Null}">
<Grid x:Name="MyGrid"
Focusable="false"
FocusManager.IsFocusScope="True"
Background="{Binding Source={x:Static Member=colors:MyColorTable.Hex1}}"
Margin="0,0,0,0"
FocusVisualStyle="{x:Null}"/>
这篇关于WPF静态绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文