Background property does not point to a dependencyobject in path '(0).(1)'

淺唱寂寞╮ 提交于 2019-12-18 07:36:26

问题


I wrote this code and got an exception:

Background property does not point to a dependencyobject in path '(0).(1)'

I saw this problem in other posts in the forum but didn't founded a solution.

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

Any help with this?


回答1:


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">



回答2:


You must set the Background property of the WrapPanel! Otherwise the WPF subsystem doesn't recognize it as a SolidColorBrush (could be another brush as well).

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

is sufficient.



来源:https://stackoverflow.com/questions/17399210/background-property-does-not-point-to-a-dependencyobject-in-path-0-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!