我不明白微软的这个Button Template Example是如何工作的...在各种状态的故事板中,它为目标类型的Border设置Panel.Background(下面的示例)。我没有看到Border以任何方式继承Panel。
将TargetProperty设置为Border.Background ...似乎以相同的方式工作。我只想了解正在发生的事情的细微差别...每次我认为我都有处理 WPF,我遇到了一些我无法解释的事情:(
<ColorAnimationUsingKeyFrames
Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)"
Storyboard.TargetName="Border">
<EasingColorKeyFrame
KeyTime="0"
Value="{StaticResource ControlPressedColor}" />
答案 0 :(得分:5)
这是因为可以重用依赖属性,Border
只是通过AddOwner
添加Panel
的属性。属性字段初始化如下:
public static readonly DependencyProperty BackgroundProperty =
Panel.BackgroundProperty.AddOwner(typeof(Border), ...
因此Panel.Background
属性与Border.Background
属性相同。