【问题标题】:Why do certain properties need to be surrounded in parenthesis..ex: Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)为什么某些属性需要用括号括起来..ex:Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)
【发布时间】:2012-09-03 16:52:36
【问题描述】:

标题几乎概括了它。我遇到了 ColorAnimation 无法正常工作的问题。我最终发现 TargetProperty 必须用括号括起来......虽然我不完全明白为什么?

有什么想法吗? (特别注意:Storyboard.TargetProperty=") 为什么一定要放在括号里?

<Style.Resources>
    <ColorAnimation x:Key="RecordingAnimation" Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" From="White" To="Blue" Duration="0:0:0.5" AutoReverse="True" RepeatBehavior="Forever"/>
    <ColorAnimation x:Key="StopRecordingAnimation" Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)" To="White" Duration="0:0:0.1"/>
</Style.Resources>

【问题讨论】:

  • Scope 看起来像是一个合理的答案.. Background.SolidColorBrush.Color 在上下文中可能没有任何意义,因为颜色是 SolidColorBrush 的属性.. 但不是 BackGround.SolidColorBrush .. 所以分离是( ) 是这里限制属性范围的方式

标签: .net wpf xaml datatrigger coloranimation


【解决方案1】:

当你引用任何一个时都需要括号

  • 多个对象和子属性,或
  • 附加的属性名称

请查看Storyboard.TargetProperty了解更多信息。

【讨论】:

    【解决方案2】:

    像解析器一样思考,它想要解析您编写的代码。如果您想在目标对象中找到一个名为 "Background.SolidColorBrush.Color" 的属性并知道该属性中设置了哪种类型,那么显然您做不到!因为目标对象中没有这样的属性。 “背景”部分是指属性名称,"SolidColorBrush" 是指已设置到属性中的对象类型。它不像 Binding 对象中的路径,您可以编写引用属性的完整路径。

    我希望这会有所帮助。

    干杯

    【讨论】:

    • 我在开始使用 XAML 时遇到了同样的问题。干杯兄弟... ;)
    猜你喜欢
    • 1970-01-01
    • 2020-07-02
    • 2021-06-06
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 2017-03-06
    • 2022-11-10
    • 2019-10-27
    相关资源
    最近更新 更多