I have silverlight animation (workig for 100% sure):
<UserControl.RenderTransform>
<CompositeTransform/>
</UserControl.RenderTransform>
and in code:
Storyboard.SetTargetProperty(myDoubleAnimation1, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateX)"));
Storyboard.SetTargetProperty(myDoubleAnimation2, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.TranslateY)"));
I tried in WPF this:
<UserControl.RenderTransform>
<TranslateTransform />
</UserControl.RenderTransform>
and:
Storyboard.SetTargetProperty(myDoubleAnimation1, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.X)"));
Storyboard.SetTargetProperty(myDoubleAnimation2, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)"));
but it crashes with exception that path (UIElement.RenderTransform).(TranslateTransform.X) cannot be resolved or sth like this.. Can you help?
Solution:
code-behind:
Storyboard.SetTargetProperty(myDoubleAnimation1, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)"));
Storyboard.SetTargetProperty(myDoubleAnimation2, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"));
markup:
<UserControl.RenderTransform>
<TransformGroup>
<TranslateTransform />
</TransformGroup>
</UserControl.RenderTransform>
As you probably figured out there is no CompositeTransform in WPF. The standard way to create Transforms is to create a TransformGroup. Then add the four types of transforms.
<UserControl.RenderTransform>
<TransformGroup>
<TranslateTransform />
<ScaleTransform />
<SkewTransform />
<RotateTransform />
</TransformGroup>
Then the animatation refers to the transform using indexer syntax.
(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With