【问题标题】:Background property does not point to a dependencyobject in path '(0).(1)'背景属性不指向路径“(0).(1)”中的依赖对象
【发布时间】:2013-06-28 06:19:39
【问题描述】:

我写了这段代码,遇到了异常:

背景属性不指向路径'(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>

有什么帮助吗?

【问题讨论】:

    标签: c# wpf animation triggers styles


    【解决方案1】:

    您很可能未能为初始背景画笔设置值。您可以使用样式设置器执行此操作,也可以直接在面板上设置一个值。样式设置器可能更好:

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

    请注意,您还可以在样式中指定TargetType 属性,这样您就不必在所有属性引用前加上WrapPanel

    <Style TargetType="WrapPanel">
    

    【讨论】:

      【解决方案2】:

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

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

      足够了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-10-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多