WPF,派生类比基类率先引发Loaded事件 ?

a18680588555 2017-11-28 03:50:43
public class BaseCustomControl:Control
{
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
Loaded += BaseCustomControl_Loaded;
}
private void BaseCustomControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
throw new NotImplementedException();
}
}
public class CustomControl3 : BaseCustomControl
{
static CustomControl3()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl3), new FrameworkPropertyMetadata(typeof(CustomControl3)));
}
public CustomControl3()
{
Loaded += CustomControl3_Loaded;
}
private void CustomControl3_Loaded(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}
}public class BaseCustomControl:Control
{
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
Loaded += BaseCustomControl_Loaded;
}
private void BaseCustomControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
throw new NotImplementedException();
}
}
public class CustomControl3 : BaseCustomControl
{
static CustomControl3()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl3), new FrameworkPropertyMetadata(typeof(CustomControl3)));
}
public CustomControl3()
{
Loaded += CustomControl3_Loaded;
}
private void CustomControl3_Loaded(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}
}在上面的代码中,CustomControl3继承自BaseCustomControl,明升分别在BaseCustomControl_Loaded方法和CustomControl3_Loaded方法处设置断点,可以看到,率先执行的是CustomControl3_Loaded方法,难道派生类比基类率先引发Loaded事件在上面的代码中,CustomControl3继承自BaseCustomControl,分别在BaseCustomControl_Loaded方法和CustomControl3_Loaded方法处设置断点,可以看到,率先执行的是CustomControl3_Loaded方法,难道派生类比基类率先引发Loaded事件
...全文
545 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

998

社区成员

发帖
与我相关
我的任务
社区描述
OpenStack
社区管理员
  • OpenStack社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧