My Silverlight系列(7)—— Control的Loaded事件与OnApplyTemplate
2009-04-25 12:04:42 来源:WEB开发网然后在Xaml中,我如此定义:
<UserControl x:Class="SilverlightApplication2.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:abcd="clr-namespace:SilverlightApplication2"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300" Loaded="UserControl_Loaded">
<Grid x:Name="LayoutRoot" Background="White">
<abcd:MyButton Loaded="MyButton_Loaded" HorizontalContentAlignment="Center">
<abcd:MyButton.Content>
<abcd:MyCheckBox Loaded="InsideCheckBox_Loaded"/>
</abcd:MyButton.Content>
</abcd:MyButton>
<abcd:MyCheckBox Loaded="OutsideCheckBox_Loaded"/>
</Grid>
</UserControl>
在后台代码中:
private void MyButton_Loaded(object sender, RoutedEventArgs e)
{
Debug.WriteLine("Button Loaded at " + DateTime.Now.ToString("o"));
}
private void InsideCheckBox_Loaded(object sender, RoutedEventArgs e)
{
Debug.WriteLine("Inside CheckBox Loaded at " + DateTime.Now.ToString("o"));
}
public override void OnApplyTemplate()
{
Debug.WriteLine("Page Applied at " + DateTime.Now.ToString("o"));
base.OnApplyTemplate();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Debug.WriteLine("Page Loaded at " + DateTime.Now.ToString("o"));
}
private void OutsideCheckBox_Loaded(object sender, RoutedEventArgs e)
{
Debug.WriteLine("Outside CheckBox Loaded at " + DateTime.Now.ToString("o"));
}
Tags:My Silverlight 系列
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接