DongJing-Yin
2019-09-27 11:48
采纳率: 100%
浏览 502

WPF中ItemControl嵌套时数据绑定子元素wei'he绑定不到?

1.问题:
根据业务场景我使用了ItemControl嵌套组合,外层的数据已经绑定到了,但是内层的没有绑上。
2.代码:
前台代码
public class DishMenuViewModel : Command.NoticeCommand
{

    private ObservableCollection<Test> originalList = new ObservableCollection<Test>();
    public ObservableCollection<Test> OriginalList
    {
        get { return originalList; }
        set { originalList = value; }
    }


    public class Test
    {

        public string TypeName { get; set; }

        public ObservableCollection<TestChild> TestChilds { get; set; }

    }

    public class TestChild
    {

        public double Number { get; set; }
        public string Diet_dish_name { get; set; }
        public int Amount { get; set; }
        public string TypeName { get; set; }

    }

    public DishMenuViewModel()
    {
        var data = new Test();
        var data1 = new TestChild()
        {
            Diet_dish_name = "测试",
            Number = 3,
            Amount = 2,
            TypeName = "大类1"
        };

        var data2 = new TestChild()
        {
            Diet_dish_name = "测试",
            Number = 3,
            Amount = 2,
            TypeName = "大类1"
        };

        var data3 = new TestChild()
        {
            Diet_dish_name = "测试",
            Number = 3,
            Amount = 2,
            TypeName = "大类1"
        };

        var data4 = new TestChild()
        {
            Diet_dish_name = "测试",
            Number = 3,
            Amount = 2,
            TypeName = "大类1"
        };
        data.TestChilds = new ObservableCollection<TestChild>();
        data.TestChilds.Add(data1);
        data.TestChilds.Add(data2);
        data.TestChilds.Add(data3);
        data.TestChilds.Add(data4);

        data.TypeName = "大类1";

        OriginalList.Add(data);
    }

}

3.尝试过换父级资源 但是已然绑定不到,希望得到帮助,x'x

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题