访问嵌套的静态const

时间:2017-02-17 10:24:12

标签: c# wpf xaml class-constants

我正在尝试在WPF中使用嵌套常量,但XAML似乎不处理嵌套的静态类。

namespace MyCommon.Constants
{
    public static class Constants
    {
        public static class Formatting
        {
            public static class DateTime
            {
                public const string BritishDateToString = "dd-MM-yy";
            }
        }
    }
}

导入命名空间

xmlns:constants="clr-namespace:MyCommon.Constants;assembly=MyCommon"

以下行给出错误

<DataGridTextColumn Binding="{Binding Path=Date, StringFormat={x:Static constants:Constants.Formatting.DateTime.BritishDateTimeToString}}" Header="Date" />

1 个答案:

答案 0 :(得分:1)

使用+访问嵌套类

<DataGridTextColumn Binding="{Binding Path=Date, StringFormat={x:Static constants:Constants+Formatting+DateTime.BritishDateTimeToString}}" Header="Date" />