473,748 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

silverlight EventHandlerLis t could not be found

3 New Member
It's easy to obtain the values for the properties and fields or invoke methods but it has been difficult for me to get the delegate from an EventInfo.

I have tried following the instructions from this website:

http://bobpowell.net/eventsubscribers.aspx
This works to display the events in WINDOWS FORMS

Expand|Select|Wrap|Line Numbers
  1. namespace WindowsFormsApplication3
  2. {
  3.     public partial class Form1 : Form
  4.     {
  5.         public Form1()
  6.         {
  7.             InitializeComponent();
  8.         }
  9.  
  10.         public Delegate[] GetEventSubscribers(object target, string eventName)
  11.         {
  12.             string WinFormsEventName = "Event" + eventName;
  13.             Type t = target.GetType();          
  14.             do
  15.             {
  16.                 FieldInfo[] fia = t.GetFields(BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic);
  17.                 foreach (FieldInfo fi in fia)
  18.                 {
  19.                     if (fi.Name == eventName)
  20.                     {
  21.                         //we've found the compiler generated event
  22.                         Delegate d = fi.GetValue(target) as Delegate;
  23.                         if (d != null)
  24.                             return d.GetInvocationList();
  25.                     }
  26.                     if (fi.Name == WinFormsEventName)
  27.                     {
  28.                         //we've found an EventHandlerList key
  29.                         //get the list
  30.                         EventHandlerList ehl = (EventHandlerList)target.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy).GetValue(target, null);
  31.                         //and dereference the delegate.
  32.                         Delegate d = ehl[fi.GetValue(target)];
  33.                         if (d != null)
  34.                             return d.GetInvocationList();
  35.                     }
  36.                 }
  37.                 t = t.BaseType;
  38.             } while (t != null);
  39.  
  40.             return new Delegate[] { };
  41.         }
  42.  
  43.         private void button1_Click(object sender, EventArgs e)
  44.         {
  45.             System.Reflection.EventInfo[] eventInfo = button1.GetType().GetEvents();
  46.             for (int i = 0; i < eventInfo.Length; i++)
  47.             {
  48.                 textBox1.Text = GetEventSubscribers(button1, eventInfo[i].Name).Length.ToString() + "    " + textBox1.Text;
  49.                 Delegate[] dels = GetEventSubscribers(button1, eventInfo[i].Name);
  50.                 string text = string.Join(", ", dels.Select(d => d.Method.Name));
  51.                 textBox2.Text = text + ". " + textBox2.Text;
  52.             }
  53.         }      
  54.     }
  55. }

However, this WILL NOT WORK FOR SILVERLIGHT because Silverlight does not have a 'EVENTHANDERLIS T'

Any ideas for how I can display the event VALUES in Silverlight?


I also tried this.

Expand|Select|Wrap|Line Numbers
  1. namespace eventhandlers
  2. {
  3.     public partial class MainPage : UserControl
  4.     {
  5.         public MainPage()
  6.         {
  7.             InitializeComponent();
  8.         }
  9.  
  10.         private void button1_Click(object sender, RoutedEventArgs e)
  11.         {
  12.             Type t = sender.GetType();
  13.             FieldInfo fi = t.GetFields(BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic);
  14.  
  15.             EventHandler eh = (EventHandler)fi.GetValue(sender);
  16.  
  17.             System.Reflection.EventInfo[] eventInfo = button1.GetType().GetEvents();                
  18.             Delegate[] dels = eh.GetInvocationList();
  19.             foreach(Delegate del in eh.GetInvocationList() )
  20.             {
  21.                 string text = del.Method.Name;
  22.                 textBlock1.Text = text + ". " + textBlock1.Text;
  23.             }
  24.         }
  25.     }
  26. }
But I get the error "FieldAccessExc eption was unhandled by user code' and ''SilverlightAp p1.MainPage.but ton1_Click (System.Object, System.Windows. RoutedEventArgs )' method 'System.Windows .Controls.Primi tives.ButtonBas e._isLoaded' failed to access the field." at

Expand|Select|Wrap|Line Numbers
  1.  EventHandler eh = (EventHandler)fi.GetValue(sender);
Sep 3 '13 #1
0 1235

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2838
by: Anders Borum | last post by:
Hello! This post relates to the implementation of the EventHandlerList class. When implementing custom events in a framework I'm developing, a handling of larger amounts of events in a class was needed and I turned my attention to the EventHandlerList. For instance, let's imagine I have 16 public events in my class and didn't use the EventHandlerList, the compiler would implement 16 delegates, each
4
4218
by: DeveloperX | last post by:
I'm having a play with EventHandlerList but the documentation is a bit ropey and I can't find any decent examples. It also doesn't seem to do what I was led to believe it would. I was under the impression that windows.forms controls used EventHandlerLists because generally most events aren't consumed so this saves memory. I can add a button to a form, and have this.button9.Click += new System.EventHandler(this.button9_Click);...
2
2075
by: Vinnie | last post by:
ok, thanks for the help. Some of you, was right: too many words, to much marketing without identifying the final user. Smithers gave the easiest answer. Now, as i wasn't enough confused, on the Microsoft web site i found these: Microsoft Expression Web Microsoft Expression Design Microsoft Expression Media
3
17670
by: Abbas | last post by:
Does anyone know how to utilize a C# class within a silverlight project? I was trying to add a reference to my non-silverlight Class Library and the VS 2008 IDE told me "You can only add project references to other Silverlight projects in the solution".
14
1430
by: Lloyd Sheen | last post by:
I have attempted several times to install this. I put this on this forum since if I go to MS site and use search it cannot find Silverlight but I have noticed several people on this forum mention using Silverlight. If I go to http://silverlight.net/ and click the download link that does not work. I can only say it is a pathetic introduction. Why it will not install (when you can find it) on Vista seems to be a common problem. Any...
4
1685
by: Ken Fine | last post by:
I know about this: http://silverlight.net/forums/14.aspx and this: http://forums.asp.net/1127.aspx Silverlight Beta 2 was announced at TechEd. I was impressed. When does Silverlight get a first-class newsgroup? -KF
1
2857
by: Faisal Shafiq | last post by:
I want to upload a file direct to the Silverlight Streaming Service from a Web Client such as silverlight application. As per our product requirement we want to upload a .WMV file directly from silverlight client to Silverlight streaming service. I tried to user WebClient and HttpWebRequest for that purpose but, unfortunately I can found the way to do so. There are some problems with both classes. 1. There is no property of get...
7
7155
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and Silverlight 2.0. To get these tools please visit this page Get Started : The Official Microsoft Silverlight Site and follow Step 1. Occasionally you find the need to have users upload multiple files at once. You could use multiple FileUpload...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.