假如有如下类: 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的内容 <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"/>都不行,语法到底应该是怎样的呢?)
请不吝赐教啊,多谢了。
{
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的内容 <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"/>都不行,语法到底应该是怎样的呢?)
请不吝赐教啊,多谢了。
<local:ConstValues x:Key="CV"/>
那么在Text那里如何使用呢?
Text={StaticResource CV.ColorValue1}这样么?提示出错