开发者

Silverlight/WPF parenthetical value syntax in a Storyboard animation

开发者 https://www.devze.com 2023-01-15 23:40 出处:网络
Somehow in my WPF studies, this detail has escaped me. I\'ve seen syntax of this sort: <UserControl.Resources>

Somehow in my WPF studies, this detail has escaped me.

I've seen syntax of this sort:

<UserControl.Resources>
    <Sto开发者_开发技巧ryboard x:Name="myStoryboard">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" ... >
...

Why is the StoryBoard.TargetProperty value surrounded by parentheses? What does that mean? Clearly it means something, because my code doesn't work without it.


This is the syntax for binding to an attached property on a class: (Class.Property)

You can read more about Dependency Properties and Attached Properties here.


From MSDN:

This syntax is generally used for one of the following cases:

  • The path is specified in XAML that is in a style or template that does not have a specified Target Type. A qualified usage is generally not
    valid for cases other than this,
    because in non-style, non-template
    cases, the property exists on an
    instance, not a type.
  • The property is an attached property.
  • You are binding to a static property.

For use as storyboard target, the property specified as propertyName must be a DependencyProperty.

0

精彩评论

暂无评论...
验证码 换一张
取 消