2

我想要一个带有常量字符串的类,例如herehere。但我希望能够在 xaml 和代码中绑定到这些值,例如:

<Window x:Class="Ccompany.Product.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:lex="http://wpflocalizeextension.codeplex.com"
        lex:ResxLocalizationProvider.DefaultAssembly="<-- would like to be able to insert the constant here -->"                
        >

您能否还提供一个示例,说明如何在 xaml 中绑定建议的“常量类”解决方案?

注意:我在发布之前尝试了不同的方法,尝试将常量包装到属性中,但我仍然无法在 xaml 中绑定它。

4

1 回答 1

2

为什么不只是这个?:

{x:Static ns:TypeName.ConstValue}

这将适用于如下常量值:

public class TypeName
{
    public const int ConstValue = 5;
}
于 2013-07-09T15:09:40.397 回答