Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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
如何在listbox数据模板WPF中绑定列表视图_Wpf - Fatal编程技术网

如何在listbox数据模板WPF中绑定列表视图

如何在listbox数据模板WPF中绑定列表视图,wpf,Wpf,我有一个名为letter的类,它包含一组对象,但当我将项源绑定到列表框时,listview数据模板中的components对象的属性为空 XAML <Window.Resources> <DataTemplate x:Key="lstDTGame"> <WrapPanel Height="30"> <TextBlock Text="{Binding Name}"></TextBlock>

我有一个名为letter的类,它包含一组对象,但当我将项源绑定到列表框时,listview数据模板中的components对象的属性为空

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; }
}
公开课信函
{
公共长ID{get;set;}
公共字符串名称{get;set;}
公共字符串值{get;set;}
公共整数总计{get;set;}
公共ObservableCollection组件{get;set;}
}
  • 您需要在构造函数或

    公共ObservableCollection组件{get;set;}= 新的可观测集合()

  • 2.您已经将listView与组件绑定,但需要绑定到ObservableCollection组件


    3.检查DataContext是否正确设置。

    还要在Letter类中添加INotifyPropertyChanged,并在组件集合中添加OnPropertyChanged事件。我认为(2)是主要问题。典型检查调试输出窗口中的绑定错误条目。