Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 绑定到WPF中的静态数组?_C#_Wpf_Data Binding - Fatal编程技术网

C# 绑定到WPF中的静态数组?

C# 绑定到WPF中的静态数组?,c#,wpf,data-binding,C#,Wpf,Data Binding,我想将WPF中的项源绑定到静态数组。我试图通过写作来做到这一点: ItemsSource="{Binding XLTT.Core.Models.names}" 但它不起作用。为什么?此外,我还看到其他人绑定到对象。绑定到静态数组可以吗,还是应该绑定到对象 编辑: 下面是定义为名称的类 namespace XLTT.Core.Models { internal class TTColumn { internal string ColumnName;

我想将WPF中的项源绑定到静态数组。我试图通过写作来做到这一点:

ItemsSource="{Binding XLTT.Core.Models.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"};
    }
}

首先,名称必须是属性

public static string[] Names {get; set;}
然后按如下方式绑定:

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

ItemsSource=“{x:Static m:TTColumn.names}”

静态数组在哪里定义?你能告诉我们这个类的定义吗?只要数组不是私有的,它是属性,就可以了@Maximus:尝试写入ItemsSource=“{Binding x:Static local:XLTT.Core.Models.names}但这不起作用ItemsSource=“{Binding Source={StaticResource XLTT.Core.Models},Path=names}”给出错误“无法解析资源”XLTT.Core.Models”。“。您知道如何解决此错误吗?命名空间是不必要的。它仍然不起作用。”。我是否需要在其他资源中定义资源?不鼓励只使用代码的答案。请添加一些解释,说明这是如何解决问题的,或者这与现有答案有何不同。
<Window
...
xmlns:m="clr-namespace:XLTT.Core.Models">

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