<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>
我在网上找到这样一段XAML代码,它的实现效果是将按钮进行旋转滚动平移,让按钮跟汽车轮子一样,但是我不知道怎么样将这段代码用后台代码实现,因为我要把这个效果做成一个Behavior,然后在后台代码里去实现这样的效果,具体代码如下:
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)"));