Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.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# 列表框数据绑定不工作_C#_Data Binding_Listbox - Fatal编程技术网

C# 列表框数据绑定不工作

C# 列表框数据绑定不工作,c#,data-binding,listbox,C#,Data Binding,Listbox,我无法理解为什么数据绑定没有按预期工作: 我创建了一个列表框,并将其ItemSource设置为我的可观察集合 我使用了这个。DataContext=这个 我初始化了我的公共可观察集合 我用实现INotifyPropertyChanged的对象填充了它 然而,数据绑定仍然不起作用。我的列表框: <ListBox Height="425" ItemsSource="{Binding headers}"> <ListBox.ItemTemplate> <

我无法理解为什么数据绑定没有按预期工作:

  • 我创建了一个列表框,并将其ItemSource设置为我的可观察集合
  • 我使用了这个。DataContext=这个
  • 我初始化了我的公共可观察集合
  • 我用实现INotifyPropertyChanged的对象填充了它
然而,数据绑定仍然不起作用。我的列表框:

<ListBox Height="425" ItemsSource="{Binding headers}">
  <ListBox.ItemTemplate>
     <DataTemplate>
           <TextBlock Text="{Binding Path=HeaderInfo}"/>
     </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

不能绑定到非属性:

<ListBox Height="425" ItemsSource="{Binding headers}">

public ObservableCollection<headerInfo> headers;

公共可观测收集头;
您需要绑定到以下属性:

public ObservableCollection<headerInfo> headers { get; set; }
publicobservableCollection头文件{get;set;}

不能绑定到非属性:

<ListBox Height="425" ItemsSource="{Binding headers}">

public ObservableCollection<headerInfo> headers;

公共可观测收集头;
您需要绑定到以下属性:

public ObservableCollection<headerInfo> headers { get; set; }
publicobservableCollection头文件{get;set;}