WPF,DataGrid里RowDetailsTemplate嵌套DataGrid的绑定问题
答案:2 悬赏:0 手机版
解决时间 2021-02-23 13:56
- 提问者网友:你挡着我发光了
- 2021-02-22 13:34
WPF,DataGrid里RowDetailsTemplate嵌套DataGrid的绑定问题
最佳答案
- 五星知识达人网友:爱难随人意
- 2021-02-22 13:55
你好:
我试了一下是可以正常显示的。不知道你的变量WeekPlanMonth和类WeekPlanModel是什么样子的。
我的代码
前台:
VM:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var weekPm = new ObservableCollection();
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();
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 MonthPlanCollection { get; set; }
}
public class MonthPlanModel
{
public int ID { set; get; }
public string Plan_ID { set; get; }
public ObservableCollection WeekPlanMonth { set; get; }
}
public class WeekPlanModel
{
public int ID { set; get; }
public string Plan_ID { set; get; }
}效果:
追问太感谢啦
我的属性定义不是在window的后台文件里的,其他的都跟你的类似,就是显示不出数据。
也就是说这种ObservableCollection里带ObservableCollection的绑定是没问题的哈?追答在后台写属性只是为了方便,不要再新建文件了。这个没什么影响。
这种ObservableCollection里带ObservableCollection的绑定是没问题的。
我试了一下是可以正常显示的。不知道你的变量WeekPlanMonth和类WeekPlanModel是什么样子的。
我的代码
前台:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var weekPm = new ObservableCollection
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
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
}
public class MonthPlanModel
{
public int ID { set; get; }
public string Plan_ID { set; get; }
public ObservableCollection
}
public class WeekPlanModel
{
public int ID { set; get; }
public string Plan_ID { set; get; }
}效果:
追问太感谢啦
我的属性定义不是在window的后台文件里的,其他的都跟你的类似,就是显示不出数据。
也就是说这种ObservableCollection里带ObservableCollection的绑定是没问题的哈?追答在后台写属性只是为了方便,不要再新建文件了。这个没什么影响。
这种ObservableCollection里带ObservableCollection的绑定是没问题的。
全部回答
- 1楼网友:山有枢
- 2021-02-22 14:16
应该是数据的变化没有更新到客户端的原因,检查一下INotifyPropertyChanged接口、PropertyChanged事件,希望对你有帮助,如还有疑问可百度Hi上联系追问我用mvvm模式的,其他的绑定都没有问题,应该不是这个原因,哎。。。追答MVVM那就是ViewModel写得有问题了,界面上只需要Binding,绑定到ObservableCollection列表
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯