c# - 访问嵌套的静态常量

标签 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" />

最佳答案

使用+访问嵌套类

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

关于c# - 访问嵌套的静态常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42295392/

相关文章:

wpf - 如何在空或透明背景上点击检测?

wpf - 在 XAML 中,在决定属性是否应采用样式时,我应该使用什么 "guidelines"?

wpf - 如何使用DynamicDataDisplay在wpf中的一个x-y平面中添加多个图形

c# - ISupportIncrementalLoading 加载比需要更多的项目

c# - System.Web.Script.Serialization.JavaScriptSerializer Sharepoint Online 事件接收器解决方案不起作用

C# Monotouch/Xamarin.iOS - UILabel 在单个字符串中包含纯文本和斜体文本

c# - 添加到绑定(bind)的 TabControl (mvvm) 后获取新选项卡的父级

c# - 当文本框为空或来自 xaml 的空格时禁用按钮

c# - 如何在解析中实现异常处理?

c# - EntityFramework,没有鉴别器的继承类