Quantcast
Channel: CSharp Forum Latest Questions
Viewing all articles
Browse latest Browse all 32056

silverlight EventHandlerList could not be found

$
0
0
I'm aware that to display the Control properties, you just need to use a code like this


System.Reflection.PropertyInfo[] propertyInfo = button1.GetType().GetProperties();
for (int i = 0; i < propertyInfo.Length; i++)
{
        textBlock.Text = i + " " + propertyInfo[i].Name + "\n" + textBlock.Text;
};

You can also get the names of the Events like this

System.Reflection.EventInfo[] eventInfo = button1.GetType().GetEvents();
for (int i = 0; i < eventInfo.Length; i++)
{
        textBlock.Text = eventInfo[i].Name + "\n" + textBlock.Text;
};

But how about to display the Event handlers? I can't just use a GetValue function like I can for propertyInfo

propertyInfo[i].GetValue(button1, null)

If I try below, I get the error "System.Reflection.EventInfo does not contain a definition for GetValue"

eventInfo[i].GetValue(button1, null)

if I try the following, I only get "???" displayed. I'm unable to display "button1_click"

for (int i = 0; i < eventInfo.Length; ++i)
{
        FieldInfo fi = senderType.GetField(eventInfo[i].Name, BindingFlags.NonPublic | BindingFlags.Instance);
         if (!Object.ReferenceEquals(null, fi))
        {
                tb4.Text = fi.GetValue(null) + "\n" + tb4.Text; continue;
        }
        PropertyInfo pi = senderType.GetProperty(eventInfo[i].Name, BindingFlags.NonPublic | BindingFlags.Instance);
        if (!Object.ReferenceEquals(null, pi))
        {
                tb4.Text = pi.GetValue(null) + "\n" + tb4.Text; continue;
        }
        tb4.Text = "???" + "\n" + tb4.Text;
}


I saw a possible solution  using 'EventHandlerList' in this Silverlight program, but when I use it, I get the error "The type or namespace name 'EventHandlerList' could not be found (are you missing a using directive or an assembly reference?)". What can I do about this?


Viewing all articles
Browse latest Browse all 32056

Trending Articles