首页 新闻 会员 周边

WPF,DataGrid里RowDetailsTemplate嵌套DataGrid的绑定问题

0
悬赏园豆:30 [已关闭问题] 关闭于 2013-10-18 08:31

就是月表里前了好几个日表,想用DataGrid的明细显示另一个DataGrid

前台:        

 1 <DataGrid ItemsSource="{Binding MonthPlanCollection}"                                        AutoGenerateColumns="True">
 2 
 3             <DataGrid.RowDetailsTemplate>
 4 
 5                 <DataTemplate>
 6 
 7                     <DataGrid ItemsSource="{Binding WeekPlanMonth}"
 8 
 9                               AutoGenerateColumns="True"/>
10 
11                 </DataTemplate>
12 
13             </DataGrid.RowDetailsTemplate>
14 
15         </DataGrid>

 

 

MonthPlanModel类型:    

 1 public class MonthPlanModel
 2 
 3     {
 4 
 5         public int ID { set; get; }
 6 
 7         public string Plan_ID { set; get; }
 8 
 9         //...
10 
11         public ObservableCollection<WeekPlanModel> WeekPlanMonth { set; get; }
12 
13     }

WeekPlanModel的元素ID,Name之类

这里ItemsSource不能绑定DataTable,因为我要手动生成列,在这我只是简单这么写,显示结果如下。

 

为什么字DataGrid里显示不了数据呢?显示出空表的行数就是WeekPlanMonth的元素个数,按理来说数据已经传过去了。为什么是空的呢?里面有数据,至少这行是真有!也就是这里MonthPlanCollection的赋值是没问题的。

求高人解答!

Shally1988的主页 Shally1988 | 初学一级 | 园豆:180
提问于:2013-10-12 15:18
< >
分享
所有回答(2)
0

你那个嵌套的DataGrid没有给列绑定呀

li-peng | 园豆:954 (小虾三级) | 2013-10-14 17:16
0

这个问题我研究了好几天,原因终于找到了。

怪我粗心,我把WeekModel的定义写错了,忘了写set和get,所以响应不了。

给自己一个教训,也给诸位绑定不了的学友提供一个反面典型吧。

太尴尬了!

Shally1988 | 园豆:180 (初学一级) | 2013-10-18 08:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册