为按钮设置TransformGroup如何通过代码实现
<Button Content="哈哈" Width="40" Height="40" RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="rotateTransform" Angle="{Binding ElementName=slider,Path=Value}" />
<TranslateTransform x:Name="translateTransform" X="{Binding ElementName=slider,Path=Value}" />
</TransformGroup>
</Button.RenderTransform>
</Button>
TranslateTransform translation = new TranslateTransform();
RotateTransform rotate = new RotateTransform();
DoubleAnimation animation = new DoubleAnimation(xTranslateFrom, xTranslateTo, TimeSpan.FromMilliseconds(xRotateDuration));
TransformGroup transform = new TransformGroup();
transform.Children.Add(rotate);
transform.Children.Add(translation);
this._StretchButton.RenderTransform = transform;
Storyboard.SetTarget(animation, this._StretchButton);
Storyboard.SetTargetProperty(animation,
new PropertyPath("X"));
Storyboard.SetTarget(animation, this._StretchButton);
Storyboard.SetTargetProperty(animation,
new PropertyPath("Angle"));
//Storyboard.SetTarget(animation, this._StretchButton);
//Storyboard.SetTargetProperty(animation,
// new PropertyPath("(xStretchButton.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)"));
Storyboard sb = new Storyboard();
sb.Duration = TimeSpan.FromMilliseconds(xRotateDuration);
sb.Children.Add(animation);
sb.Begin();