2

I'm trying to use a nested constant within WPF, but XAML doesn't seem to handle nested static classes.

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

Import the namespace

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

The following lines gives an error

<DataGridTextColumn Binding="{Binding Path=Date, StringFormat={x:Static constants:Constants.Formatting.DateTime.BritishDateTimeToString}}" Header="Date" />
wonea
  • 4,783
  • 17
  • 86
  • 139

1 Answers1

6

Use + for accessing nested classes

<DataGridTextColumn Binding="{Binding Path=Date, StringFormat={x:Static constants:Constants+Formatting+DateTime.BritishDateTimeToString}}" Header="Date" />
tchrikch
  • 2,428
  • 1
  • 23
  • 43