Can I access ItemsHost of ItemsControl using reflection?

前端 未结 1 474
感情败类
感情败类 2021-01-13 15:45

I\'m creating custom ItemsControl that is derived from DataGrid. I need to access ItemsHost that is the Panel that actually holds rows

1条回答
  •  被撕碎了的回忆
    2021-01-13 16:21

    Yes I can. It is simple - I've just created property in class inheriting from DataGrid:

    protected Panel ItemsHost {
        get {
            return (Panel) typeof (MultiSelector).InvokeMember("ItemsHost",
                BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Instance,
                null, this, null);
        }
    }
    

    It works like a charm :). I can get the value of ItemsHost internal property of the ItemsControl class. This way I can access any non-protected properties.

    0 讨论(0)
提交回复
热议问题