就是月表里前了好几个日表,想用datagrid的明细显示另一个datagrid
前台:
<DataGrid ItemsSource="{Binding MonthPlanCollection}" AutoGenerateColumns="True">
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DataGrid ItemsSource="{Binding WeekPlanMonth}"
AutoGenerateColumns="True"/>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
MonthPlanModel类型:
public class MonthPlanModel
{
public int ID { set; get; }
public string Plan_ID { set; get; }
。。。。等等
public ObservableCollection<WeekPlanModel> WeekPlanMonth { set; get; }
}
WeekPlanModel的元素ID,Name之类
为什么字datagrid里显示不了数据呢?显示出空表的行数就是WeekPlanMonth的元素个数,按理来说数据已经传过去了。为什么是空的呢?里面有数据,至少这行是真有!也就是这里MonthPlanCollection的赋值是没问题的。
求高人解答!
我用mvvm模式的,其他的绑定都没有问题,应该不是这个原因,哎。。。
追答MVVM那就是ViewModel写得有问题了,界面上只需要Binding,绑定到ObservableCollection列表
你好:
我试了一下是可以正常显示的。不知道你的变量WeekPlanMonth和类WeekPlanModel是什么样子的。
我的代码
前台:
<DataGrid ItemsSource="{Binding MonthPlanCollection}" AutoGenerateColumns="True">VM:
public partial class MainWindow : Window效果:
太感谢啦
我的属性定义不是在window的后台文件里的,其他的都跟你的类似,就是显示不出数据。
也就是说这种ObservableCollection里带ObservableCollection的绑定是没问题的哈?
在后台写属性只是为了方便,不要再新建文件了。这个没什么影响。
这种ObservableCollection里带ObservableCollection的绑定是没问题的。