当前位置: 代码迷 >> Silverlight >> 为按钮设置TransformGroup怎么通过代码实现
  详细解决方案

为按钮设置TransformGroup怎么通过代码实现

热度:2443   发布时间:2013-02-26 00:00:00.0
为按钮设置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>

我在网上找到这样一段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)"));
  相关解决方案