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事件