Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding to static array in WPF? [duplicate]

I want to bind an item source in my WPF to a static array. I have tried to do this by writing:

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

But it doesn't work. Why? Additionally, I have seen others bind to objects. Is it ok to bind to a static array or should I be binding to an object instead?

EDIT:

Here is the class with names definition.

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"};
    }
}
like image 903
user1283776 Avatar asked Jul 29 '26 16:07

user1283776


1 Answers

For starters, Names needs to be property

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

Then bind as follows:

 ItemsSource="{Binding Source={StaticResource TTColumn}, Path=Names}"
like image 113
Maximus Avatar answered Aug 01 '26 08:08

Maximus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!