The run order about Loaded event and OnApplyTemplate in custom control of Silverlight 2 beta 2
来源:互联网 发布:晋中教育网网络教研 编辑:程序博客网 时间:2024/05/19 11:44
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 Calendar Control and the DayRender Event in ASP.Net
- use code to generate Silverlight Controls at run time, and serialize the control into XAML file
- zz - transcript of Defining and Using Shared Resources in a Custom Control Library
- What is the difference between User Control and Custom Control?
- How To Call Run() Method of the Microsoft Script Control in C++
- Microsoft Windows Vista Beta 2 Order Confirmation and Product Key
- Silverlight 2.0 beta 2
- 怎么创建silverlight custom control
- Send Custom Event to Host (Windows Form) from a WPF Control -Part 2
- using JS to control two select(html),the data can be loaded from database and XML,and show in the select
- Implement Custom Paging in the ASP.Net Datagrid Control...
- About stack and heap in JAVA(2)
- About the Usage of fseek and ftell
- About the application of lambda and relayCommand
- About Delegate and Event
- Upgrading to Silverlight Tools Beta 2 and Visual Studio 2008 SP1 Beta
- Print the numbers of form 2^i.5^j in increasing order -- Google
- asp.net页面回传与js调用服务端事件、PostBack的原理详解(转)
- 思想的落叶
- Java 规则引擎的设置第一步
- Program E的Flash前端
- Struts实现图片上传
- The run order about Loaded event and OnApplyTemplate in custom control of Silverlight 2 beta 2
- Welcome, Kevin & his friends
- informix存储过程中的截取字符串、取当天日期
- 使用CXF时,在Client端用于把 Date 类型转换成 XMLGregorianCalendar
- Java研习计划
- 开发之准备:为目标设备创建映像
- 流行AJAX框架大比拼
- script 乱码问题
- ACE中网络通讯编程基本架构