首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

wpf 资源声明解决思路

2012-05-14 
wpf 资源声明假如有如下类:C# codepublic class ConstValues{const string ColorValue1 Redconst str

wpf 资源声明
假如有如下类:

C# code
    public class ConstValues    {        const string ColorValue1 = "Red";        const string ColorValue2 = "Green";    }    /// <summary>    /// Interaction logic for Window1.xaml    /// </summary>    public partial class Window1 : Window    {        public Window1()        {            InitializeComponent();        }    }

我想在Window1的Xaml部分声明资源以应用ConstValues的数据,比如我想实现TextBlock1里边显示ColorValue1的内容,TextBlock2里边显示ColorValue2的内容
C# code
  <Window.Resources>        <!--ConstValues资源的声明-->    </Window.Resources>    <StackPanel>        <TextBlock x:Name="TextBlock1"/><!--设置Text属性为资源中相应的内容-->        <TextBlock x:Name="TextBlock2"/><!--设置Text属性为资源中相应的内容-->    </StackPanel>

具体代码的语法应该是什么样子的呢?
(加入我已经声明了local为程序命名空间,我声明了<local:ConstValues x:Key="CV"/> 或<local:ConstValues.ColorValue1 x:Key="CVC1"/> 或<local:ConstValues:ColorValue1 x:Key="CVC1"/>都不行,语法到底应该是怎样的呢?)
请不吝赐教啊,多谢了。

[解决办法]
Text="{Binding StaticResource CV.ColorValue1}"

热点排行