C# WPF绑定问题

C# WPF绑定问题,c#,wpf,binding,C#,Wpf,Binding,我有一个目标: class a { public string Application; public DateTime From, To; } 我在此声明: ObservableCollection<a> ApplicationsCollection = new ObservableCollection<a>(); 我收到一堆错误,但在我的列表视图中没有显示任何内容: Syste

我有一个目标:

    class a 
    { 
        public string Application; 
        public DateTime From, To;
    }
我在此声明:

    ObservableCollection<a> ApplicationsCollection = 
        new ObservableCollection<a>();
我收到一堆错误,但在我的列表视图中没有显示任何内容:

System.Windows.Data Error: 39 : BindingExpression path error: 'Application' property not found on 'object' ''a' (HashCode=60325168)'. BindingExpression:Path=Application; DataItem='a' (HashCode=60325168); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Error: 39 : BindingExpression path error: 'From' property not found on 'object' ''a' (HashCode=60325168)'. BindingExpression:Path=From; DataItem='a' (HashCode=60325168); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Error: 39 : BindingExpression path error: 'To' property not found on 'object' ''a' (HashCode=60325168)'. BindingExpression:Path=To; DataItem='a' (HashCode=60325168); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
很明显,它将对象视为具有类型
a
,并且a显然具有正确的属性,那么为什么这不起作用呢?

查看本文-
我认为您缺少ItemsSource=指令。

好的,您使用字段,但需要属性

class a 
{ 
    public string Application
    {
       get;set;
    }
    public DateTime From
    {
       get;set;
    } 
    public DateTime To
    {
       get;set;
    } 

}

看起来WPF无法直接绑定到字段,您必须使用如下属性:

class a
{
    public string Application { get; set; }
    public DateTime From { get; set; }
    public DateTime To { get; set; }
}

他在问题中表示,他将集合分配给代码隐藏中的ItemsSource。这是通过代码而不是XAML设置的。应该没问题,不是吗?应该没问题,但试着把它移到xaml。正如马特提到的那样,我错过了问题中的那一行。也许你也需要把这门课标记为公共课。。。
class a 
{ 
    public string Application
    {
       get;set;
    }
    public DateTime From
    {
       get;set;
    } 
    public DateTime To
    {
       get;set;
    } 

}
class a
{
    public string Application { get; set; }
    public DateTime From { get; set; }
    public DateTime To { get; set; }
}