在WPF DataGrid中绑定RowDetails [英] Binding RowDetails in WPF DataGrid
本文介绍了在WPF DataGrid中绑定RowDetails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎找不到解决方法.
I cant seem to find how to do this.
我不明白为什么rowdetailstemplate的datacontext成为datagrid父级的datacontext.清除时,应从datagrid项目源中选择行项目.
I dont see why the datacontext for a rowdetailstemplate becomes the datacontext of the datagrid parent. When it cleary should choose the rowitem from the datagrid itemssource.
<DataGrid Grid.Row="1" x:Name="DataGrid" ItemsSource="{Binding Collection}"
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<TextBox Text="{Binding WhyDoesThisBindingUseDataContextOfDatGridParentAndNotTheRowDataObject}"/>
</DataTemplate>
</DataGrid.RowDetailsTemplate></DataGrid>
如何获取rowdataobject作为模板的数据上下文?
How can i get the rowdataobject as the datacontext for my template?
推荐答案
看看视觉树.
您绑定到ItemsSource的对象不适用于RowDetailsTemplate.它需要DataGrid Parent的DataContext.
Object which you binds to ItemsSource doesn't apply to RowDetailsTemplate. It takes DataContext of DataGrid Parent.
这篇关于在WPF DataGrid中绑定RowDetails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文