2017-05-21 63 views
0

我有一個名爲letter的類,其中包含對象集合,但是當我將項目源綁定到列表框時,listview數據模板中的組件對象的屬性是空如何在列表框數據模板中綁定列表視圖WPF

XAML

<Window.Resources> 
    <DataTemplate x:Key="lstDTGame"> 
     <WrapPanel Height="30"> 
      <TextBlock Text="{Binding Name}"></TextBlock> 
      <ListView></ListView> 
      <ListView ItemsSource="{Binding Path=Component}"> 
       <ListView.View> 
        <GridView AllowsColumnReorder="True" 
           ColumnHeaderToolTip="Employee Information"> 
         <GridViewColumn Header="{Binding Path=Name}" 
             Width="100" 
             DisplayMemberBinding="{Binding Path=Point}" /> 
        </GridView> 
       </ListView.View> 
      </ListView> 
     </WrapPanel> 
    </DataTemplate> 
</Window.Resources> 

public class Letter 
{ 
    public long ID { get; set; } 
    public string Name { get; set; } 
    public string Value { get; set; } 
    public int Total { get; set; } 
    public ObservableCollection<Component> Components { get; set; } 
} 

回答

1
  1. 您需要在構造函數中初始化ObservableCollection或

    public ObservableCollection Components {get;組; } = new ObservableCollection < Component>();

2.您已將ListView綁定到Component,但您需要綁定到ObservableCollection組件。

3.檢查DataContext設置是否正確。

+1

還要在Letter類中添加INotifyPropertyChanged,並在Component集合中添加OnPropertyChanged事件。 –

+1

我認爲(2)是主要問題。典型*檢查您的調試輸出窗口是否有綁定錯誤條目*。 – grek40