0
votes

In a UserControl I have a Storyboard for an animation that must use Storyboard.TargetName.

I want to start/stop the animnation via a DataTrigger.
A DataTrigger can be added to a Style.
But: A Storyboard tree in a Style cannot specify a TargetName.

And: Triggers collection members must be of type EventTrigger.
Therefore I cannot add the DataTrigger to UserControl.Triggers.

What should I do (in terms of solving the problem)?

1
I have an idea how to fix it, but can you please show the relevant XAML? Please at least include the Storyboard, the DataTrigger and the two UI elements involved.Sheridan
Ok, don't worry, I don't think that I need it now... hopefully you can make sense of my answer without it.Sheridan

1 Answers

1
votes

It would have been easier to explain this if you had shown the relevant code, but I'll have a go anyway. The answer is simpler than you think... just move the Storyboard to the element that you would have specified as the Storyboard target.

For example, if you were trying to add a Storyboard to a ToggleButton to change the Opacity of a TextBlock when the user clicks, or checks the Button, then you can just move the Storyboard to the TextBlock.Style.Triggers collection and set the DataTrigger to trigger when the ToggleButton.IsChecked value is True.

The basic idea is this:

Instead of using a DataTrigger in control A to change something from control B when something happens in control A, reverse the situation. Use the DataTrigger in control B to change something in control B when something happens in control A.