我可以使用反射访问的ItemsControl的ItemsHost? [英] Can I access ItemsHost of ItemsControl using reflection?

查看:209
本文介绍了我可以使用反射访问的ItemsControl的ItemsHost?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建自定义的的ItemsControl 是从的DataGrid 导出。我需要访问ItemsHost那就是面板实际持有的DataGrid 行。我所看到的丑陋的索姆技巧来做到这一点,但我认为他们差那么使用反射。
这样我就可以访问ItemsHost使用反射?怎么样?

I'm creating custom ItemsControl that is derived from DataGrid. I need to access ItemsHost that is the Panel that actually holds rows of DataGrid. I have seen som ugly tricks to do that but I consider them worse then using reflection. So can I access ItemsHost using reflection ? And how ?

推荐答案

我可以的。这很简单 - 我刚刚创建的类从的DataGrid 继承财产:

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);
    }
}



它的工作原理就像一个魅力:)。我可以得到的ItemsControl 类的<​​code> ItemsHost 内部属性的值。这样我可以访问任何非保护性能。

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.

这篇关于我可以使用反射访问的ItemsControl的ItemsHost?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆