0

Is there a way to interrogate a UIElement to determine which Storyboards are affecting it?

For example, Storyboard resources can be defined in a number of places (eg Application.Resources, Window.Resources, Control.Resources). If you have a reference to a control being affected by a Storyboard (say a RotateTransform), is there any way to interrogate the control to discover that Storyboard?

What I don't want is to obtain the reference of the Storyboard simply by knowing it's name.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Zodman
  • 3,178
  • 2
  • 32
  • 38
  • I don't think the UIElements know about Storyboards at all, But the Storyboards will know about the Elements through the `Target` property. So perhaps you could go backward and iterrogate the storyboards for the UIElement you want – sa_ddam213 Jun 26 '13 at 02:30
  • Interrogate the Storyboards where though @sa_ddam213? They could be defined anywhere! Is there a central Storyboards location? – Zodman Jun 27 '13 at 00:54

1 Answers1

0

There is no direct way to know what you asking, however you can use following code :

Suppose "btn" is the control for which you are searching Storyboard.

  Button btn = new Button();
        List<Storyboard> lst = new List<Storyboard>();
        foreach (var item in this.Resources)
        {
            if (item is Storyboard)
            {
                Storyboard temp = item as Storyboard;

                foreach (var animation in temp.Children)
                {
                    if (animation.GetValue(Storyboard.TargetProperty) == btn)
                    {
                        lst.Add(temp);
                    }
                }
            }
        }
Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Shivam cv
  • 526
  • 5
  • 16
  • This assumes the Storyboard is defined in "this", which may not be the case. – Zodman Jun 27 '13 at 00:52
  • Sure @Shivamcv. My point is though that there are any number of NameScopes that could contribute the Storyboard between where you are performing the look up and application resources. You don't necessarily know each place to check, so this is not a complete solution. – Zodman Jul 01 '13 at 01:42