我想在WPF中RenderTransform
WebBrowser。我能够RenderTransform WPF按钮。
请使用按钮代码检查以下工作:
XAML:
<Window x:Class="WPFAnimationStyles.MoveButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MoveButton" Height="400" Width="550">
<Grid>
<Button Name="myButton" Margin="77,105,81,107" >
<Button.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Button.RenderTransform>
</Button>
<Button Content="Show Animation" Height="23" HorizontalAlignment="Left" Margin="144,332,0,0" Name="button1" VerticalAlignment="Top" Width="115" Click="button1_Click" />
</Grid>
CS代码:
using System;
using System.Windows;
using System.Windows.Media.Animation;
namespace WPFAnimationStyles
{
/// <summary>
/// Interaction logic for MoveButton.xaml
/// </summary>
public partial class MoveButton : Window
{
public MoveButton()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ShowAnimation();
}
public void ShowAnimation()
{
var board = new Storyboard();
var animation1 = new DoubleAnimationUsingKeyFrames();
var animation2 = new DoubleAnimationUsingKeyFrames();
animation1.SetValue(Storyboard.TargetNameProperty, "myButton");
animation1.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"));
animation2.SetValue(Storyboard.TargetNameProperty, "myButton");
animation2.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)"));
animation1.BeginTime = new TimeSpan(0, 0, 0);
animation2.BeginTime = new TimeSpan(0, 0, 0);
var keyFrame1 = new SplineDoubleKeyFrame();
var keyFrame2 = new SplineDoubleKeyFrame();
keyFrame1.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 2));
keyFrame2.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 2));
keyFrame1.Value = 268;
keyFrame2.Value = -90;
animation1.KeyFrames.Add(keyFrame1);
animation2.KeyFrames.Add(keyFrame2);
board.Children.Add(animation1);
board.Children.Add(animation2);
board.RepeatBehavior = RepeatBehavior.Forever;
board.AutoReverse = true;
board.Stop();
board.Begin(this);
}
}
}
我想用 WebBrowser ... 控件做同样的动画。
请帮忙。