I 've created a customer control menulink. CS in Silverlight 2beta2, and the code like this:
- Public class menulink: Control
- {
- Public menulink ()
- {
- Defaultstylekey = typeof (menulink );
- This. Loaded + = new routedeventhandler (menulink_loaded );
- }
- Void menulink_loaded (Object sender, routedeventargs E)
- {
- }
- Public override void onapplytemplate ()
- {
- Base. onapplytemplate ();
- }
- }
There is a canvas named 'menu 'in page 'page. XAML', and I add the menulink into the canvas dynamicly:
- Public page ()
- {
- Initializecomponent ();
- This. Loaded + = new routedeventhandler (page_loaded );
- }
- Void page_loaded (Object sender, routedeventargs E)
- {
- Menulink ML = new menulink (true );
- Canmenu. Children. Clear ();
- Canmenu. Children. Add (ML );
- }
In this situation, the event in menulink. CS are called by this orders:
- 1. Public menulink (bool)
- 2. Void menulink_loaded (Object sender, routedeventargs E)
- 3. Public override void onapplytemplate ()
But if I add the menulink after downloading a XML file in page. CS like this:
- Public page ()
- {
- Initializecomponent ();
- This. Loaded + = new routedeventhandler (page_loaded );
- }
- Void page_loaded (Object sender, routedeventargs E)
- {
- WebClient = new WebClient ();
- WebClient. downloadstringcompleted + = new downloadstringcompletedeventhandler (webclient_downloadstringcompleted );
- WebClient. downloadstringasync (New uri ("A. xml", urikind. Relative ));
- }
- Void webclient_downloadstringcompleted (Object sender, downloadstringcompletedeventargs E)
- {
- Menulink ML = new menulink (true );
- Canmenu. Children. Clear ();
- Canmenu. Children. Add (ML );
- }
Then the order of events/methods called in menulink. CS like this:
- 1. Public menulink (bool)
- 2. Public override void onapplytemplate ()
- 3. Void menulink_loaded (Object sender, routedeventargs E)
I really don't know why ?????