15

我写了这段代码并得到了一个异常:

背景属性不指向路径“(0).(1)”中的依赖对象

我在论坛的其他帖子中看到了这个问题,但没有找到解决方案。

<WrapPanel.Style>
  <Style>
    <Style.Triggers>
      <Trigger Property "WrapPanel.Visibility" Value="Visible">                            
        <Trigger.EnterActions>
          <BeginStoryboard HandoffBehavior="Compose">
            <Storyboard RepeatBehavior="Forever" AutoReverse="True">
              <ColorAnimation 
                Storyboard.TargetProperty="(WrapPanel.Background).(SolidColorBrush.Color)"
                Duration="00:00:01" To="Red"/>
            </Storyboard>
          </BeginStoryboard>
        </Trigger.EnterActions>
      </Trigger>
    </Style.Triggers>
  </Style>
</WrapPanel.Style>

有什么帮助吗?

4

2 回答 2

25

You most likely failed to set a value for the initial background brush. You can either do so with a style setter, or else just set a value on the panel directly. The style setter is probably better:

<Setter Property="Background">
    <Setter.Value>
        <SolidColorBrush Color="Blue"/>
    </Setter.Value>
</Setter>

Note that you can also specify the TargetType property on your style, so that you don't have to prefix all property reference with WrapPanel:

<Style TargetType="WrapPanel">
于 2013-07-01T07:30:36.693 回答
6

您必须设置 WrapPanel 的 Background 属性!否则 WPF 子系统不会将其识别为 SolidColorBrush(也可能是另一个画笔)。

<WrapPanel Background="White">
...
</WrapPanel>

足够了。

于 2013-07-01T07:33:46.133 回答