RowDetailsTemplate中的数据绑定不起作用

时间:2013-05-18 09:56:58

标签: wpf data-binding datagrid

我有简单的Datagrid与绑定,这个正常工作,并在RowDetailsRemplate内部另一个Datagrid,但在这种情况下绑定不起作用。你能帮我解决这个问题吗?

XAML:

 <DataGrid  Name="datagrid"  Margin="5,0,5,0" GridLinesVisibility="None" CanUserAddRows="False" ItemsSource="{Binding nowy}" >
            <DataGrid.Columns>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Expander Name="expander" IsExpanded="False" Collapsed="sw" Expanded="pos"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
            <DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <StackPanel>
                         <DataGrid Name="wz" ItemsSource="{Binding flight_list}"/> 
                    </StackPanel>
                </DataTemplate>
            </DataGrid.RowDetailsTemplate>
        </DataGrid>

C#:

 public ObservableCollection<flight> flight_list { get; set; }
    public ObservableCollection<subject> nowy { get; set; }
nowy = new  ObservableCollection<subject>() {
            {new subject(){ Przedmiot = "J.angielski", Nauczyciel = "B.A.Krawczyk", Sala = "120", Poziom = "Średnio-zaawansowany", Status = "Uczeń"}},
            { new subject(){Przedmiot = "polski", Nauczyciel = "zły", Sala = "130", Poziom = "podstawowy", Status = "gey"}}
        };
 flight_list = new ObservableCollection<flight>(){new flight(){From = "Warsaw", To = "Florida", schedule = new List<string>(){"12-02-2013", "12-03-2012", "31-2"}}};
 DataContext = this;

1 个答案:

答案 0 :(得分:0)

首先,我看不到flightsubject之间的联系。其次,根据您的代码,将行详细信息DataGrid项绑定到flight,这不是列表而是类型。无论如何,如果你想将它绑定到flight_list,除非你将它指定为Source而不是Path,那么它将在flight类型的上下文中搜索subject,这不会将航班属性公开为我可以看到。此外,您不需要使用ItemContainerTemplate标准DataTemplate即可,因为您使用的DataGridItemsControl