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?????
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。