The run order about Loaded event and OnApplyTemplate in custom control of Silverlight 2 beta 2

The run order about Loaded event and OnApplyTemplate in custom control of Silverlight 2 beta 2,第1张

概述I' ve created a customer control MenuLink.cs in silverlight 2beta2, and the code like this: public class MenuLink : Control  {          public MenuLink( )         {                       DefaultStyleK

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 'canMenu' 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 a ) 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 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 a ) 2. public overrIDe voID OnApplyTemplate() 3. voID Menulink_Loaded(object sender, RoutedEventArgs e)

 

I really don't kNow why?????

总结

以上是内存溢出为你收集整理的The run order about Loaded event and OnApplyTemplate in custom control of Silverlight 2 beta 2全部内容,希望文章能够帮你解决The run order about Loaded event and OnApplyTemplate in custom control of Silverlight 2 beta 2所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1054436.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存