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

就是月表里前了好几个日表,想用datagrid的明细显示另一个datagrid前台:<DataGridItemsSource="{BindingMonthPlanColl... 就是月表里前了好几个日表,想用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的赋值是没问题的。
求高人解答!
展开
 我来答
zhouxiang_1216
2013-10-12 · TA获得超过2590个赞
知道大有可为答主
回答量:1286
采纳率:33%
帮助的人:1354万
展开全部
应该是数据的变化没有更新到客户端的原因,检查一下INotifyPropertyChanged接口、PropertyChanged事件,希望对你有帮助,如还有疑问可百度Hi上联系
追问
我用mvvm模式的,其他的绑定都没有问题,应该不是这个原因,哎。。。
追答
MVVM那就是ViewModel写得有问题了,界面上只需要Binding,绑定到ObservableCollection列表
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
RXC55555
推荐于2016-08-12 · TA获得超过135个赞
知道小有建树答主
回答量:121
采纳率:0%
帮助的人:115万
展开全部

你好:

        我试了一下是可以正常显示的。不知道你的变量WeekPlanMonth和类WeekPlanModel是什么样子的。


我的代码

前台:

<DataGrid ItemsSource="{Binding MonthPlanCollection}"  AutoGenerateColumns="True">
     <DataGrid.RowDetailsTemplate>
           <DataTemplate>
                <DataGrid ItemsSource="{Binding WeekPlanMonth}" AutoGenerateColumns="True"/>
           </DataTemplate>
     </DataGrid.RowDetailsTemplate>
</DataGrid>

VM:

  public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            var weekPm = new ObservableCollection<WeekPlanModel>();
            weekPm.Add(new WeekPlanModel(){ID = 1,Plan_ID = "One"} );
            weekPm.Add(new WeekPlanModel() { ID = 2, Plan_ID = "Two" });
            weekPm.Add(new WeekPlanModel() { ID = 3, Plan_ID = "Three" });

            MonthPlanCollection = new ObservableCollection<MonthPlanModel>();
            MonthPlanCollection.Add(new MonthPlanModel() {ID = 1,Plan_ID = "A",WeekPlanMonth = weekPm});
            MonthPlanCollection.Add(new MonthPlanModel() { ID = 2, Plan_ID = "B" });
            MonthPlanCollection.Add(new MonthPlanModel() { ID = 3, Plan_ID = "C" });
            DataContext = this;
        }

        public ObservableCollection<MonthPlanModel> MonthPlanCollection { get; set; }
    }

     public class MonthPlanModel
    {
        public int ID { set; get; }
        public string Plan_ID { set; get; }
        public ObservableCollection<WeekPlanModel> WeekPlanMonth { set; get; }
    }
     public class WeekPlanModel
     {
         public int ID { set; get; }
         public string Plan_ID { set; get; }
     }

效果:

追问
太感谢啦

我的属性定义不是在window的后台文件里的,其他的都跟你的类似,就是显示不出数据。
也就是说这种ObservableCollection里带ObservableCollection的绑定是没问题的哈?
追答
在后台写属性只是为了方便,不要再新建文件了。这个没什么影响。

这种ObservableCollection里带ObservableCollection的绑定是没问题的。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式