Reputation: 746
I'm not really sure how to get started on this and I sure could use some direct advice (even if it is not possible).
I have 3 controls hosted on a page. Two of them have a Storyboard
that runs when the controls are loaded. One of them doesn't. But as I have more controls that are later added, some of which will have the Storyboard
and some of which won't (they are dynamic, so there is no way to know in advance as these are....well, it's a long story).
So what I want to do is from the host page, see if a control has a field of "Storyboard sb" and if so, hook to it it so that when it is finished on the control, the host page does something.
I've looked quite a bit around System.Reflection and I think I'm in the right spot of the help files, but can't figure out where/how I should be looking to a) see if a control has this field, b) hook to it's "Completed" event if so, c) then remove the handler.
Any advice/direction?
Upvotes: 1
Views: 106
Reputation: 93601
Use Dependency properties instead (in this case a Dependency property of type Storyboard).
DPs allow arbitrary values to be assigned to objects that know nothing about the values. They can also be assigned in the Xaml as well as dynamically added from code. It is also faster than reflection.
Handy Snippet to generate DPs here: Silverlight Dependency Property Snippet (has a minor typo in the code generated, wrong case, you will need to correct the snippet)
Upvotes: 1
Reputation: 6570
An alternative, relatively straight forward, way might be to "abuse" the Tag property of the controls to indicate if they should use the storyboard. Although I'm not a fan (to say the least) of these kinds of scenario's, it's simple and quick enough (and dirty ;)), and you can stay away from reflection.
Upvotes: 0