Linking to a static array in WPF?

I want to bind an element source in my WPF to a static array. I tried to do it by writing:

ItemsSource="{Binding XLTT.Core.Models.names}"

      

But that won't work. What for? Also, I've seen others bind to objects. Can I bind to a static array or should I bind to an object instead?

EDIT:

Here is a class with a definition names

.

namespace XLTT.Core.Models
{
    internal class TTColumn
    {
        internal string ColumnName;
        internal string ColumnType;
        internal int ColumnOrder;
        internal bool IsRequired;
        internal int ColumnWidth;

        public static string[] names = {"Matt", "Joanne", "Robert"};
    }
}

      

+3


source to share


2 answers


First, the names must be a property

public static string[] Names {get; set;}

      



Then link like this:

 ItemsSource="{Binding Source={StaticResource TTColumn}, Path=Names}"

      

+2


source


<Window
...
xmlns:m="clr-namespace:XLTT.Core.Models">

ItemsSource="{x:Static m:TTColumn.names}"

      



0


source







All Articles