system.reflection.eventinfo不包含GetValue的定义

时间:2013-08-21 05:39:19

标签: c# silverlight events reflection checkbox

很容易获取属性和字段的值或调用方法,但是我很难显示事件处理程序。我不能像使用PropertyInfo

那样使用GetValue函数

我已尝试按照本网站的说明操作:

http://bobpowell.net/eventsubscribers.aspx这适用于在WINDOWS FORMS中显示事件

然而,这不适用于SILVERLIGHT,因为Silverlight没有'EVENTHANDERLIST'

关于如何在Silverlight中显示事件VALUES的任何想法?

我试过这个

namespace eventhandlers
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Type t = sender.GetType();
            FieldInfo fi = t.GetFields(BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic);

            EventHandler eh = (EventHandler)fi.GetValue(sender);

            System.Reflection.EventInfo[] eventInfo = button1.GetType().GetEvents();                
            Delegate[] dels = eh.GetInvocationList();
            foreach(Delegate del in eh.GetInvocationList() )
            {
                string text = del.Method.Name;
                textBlock1.Text = text + ". " + textBlock1.Text;
            }
        }
    }
}

但我收到错误“FieldAccessException未被用户代码处理”和''SilverlightApp1.MainPage.button1_Click(System.Object,System.Windows.RoutedEventArgs)'方法'System.Windows.Controls.Primitives.ButtonBase._isLoaded'未能进入该领域。“在

EventHandler eh = (EventHandler)fi.GetValue(sender);

0 个答案:

没有答案