简体   繁体   English

RowDetailsTemplate中的数据绑定不起作用

[英]Databinding in RowDetailsTemplate doesn't work

I have simple Datagrid with binding and this one works correctly and inside RowDetailsRemplate another Datagrid but in that case binding does not work. 我有带有绑定的简单Datagrid,它可以正常工作,并且在RowDetailsRemplate内可以使用另一个Datagrid,但是在这种情况下,绑定不起作用。 Can you give me a hand with sorting this out? 您能帮我解决这个问题吗?

XAML: 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#: 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;

First I don't see a connection between flight and subject . 首先,我看不到flightsubject之间的联系。 Second you bind row details DataGrid items to flight which is not a list but a type, according to your code. 其次,根据您的代码,将行详细信息DataGrid项绑定到flight ,这不是列表而是一种类型。 Anyway if you want to bind it to flight_list unless you specify it as a Source and not Path then it will search for flight in context of subject type, which does not expose flight property as far as I can see. 无论如何,如果您要将其绑定到flight_list除非您将其指定为Source而不是Path,否则它将在subject类型的上下文中搜索flight ,据我所知,该类型不会公开flight属性。 Also you don't need to use ItemContainerTemplate , standard DataTemplate will do since you use DataGrid which is ItemsControl 你也不必使用ItemContainerTemplate ,标准DataTemplate会做,因为你使用DataGridItemsControl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM