2010-03-03 89 views
4

好吧,夥計們,wpf靜態綁定問題

我有一個嚴重的問題。

我有靜電性能提供一些顏色的十六進制字符串一個靜態類:

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一個用戶控件,就像這樣:

<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事件,因爲一旦啓動應用程序,顏色就不會更新。

回答

7

得到它:

<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}"/>