3
A
回答
5
使用下面的XAML:
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas x:Name="LayoutRoot">
<Rectangle x:Name="myBox" Fill="Red" Height="100" Width="100" Canvas.Left="0" Canvas.Top="0" />
</Canvas>
</UserControl>
你可以創建動畫編程方式使用這樣的:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
Loaded += MainPage_Loaded;
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var moveAnimation = CreateAnimation(this.myBox);
moveAnimation.Begin();
}
public Storyboard CreateAnimation(FrameworkElement element)
{
var storyboard = new Storyboard();
var downAnimation = new DoubleAnimationUsingKeyFrames();
Storyboard.SetTarget(downAnimation, element);
Storyboard.SetTargetProperty(downAnimation, new PropertyPath(Canvas.TopProperty));
downAnimation.KeyFrames.Add(new EasingDoubleKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)),
Value = 200
});
storyboard.Children.Add(downAnimation);
var overAnimation = new DoubleAnimationUsingKeyFrames();
Storyboard.SetTarget(overAnimation, element);
Storyboard.SetTargetProperty(overAnimation, new PropertyPath(Canvas.LeftProperty));
overAnimation.KeyFrames.Add(new EasingDoubleKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2)),
Value = 0
});
overAnimation.KeyFrames.Add(new EasingDoubleKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4)),
Value = 200
});
storyboard.Children.Add(overAnimation);
return storyboard;
}
}
相關問題
- 1. 以C編程方式創建Silverlight動畫#
- 2. 如何創建動畫方面編程
- 3. 以編程方式在Silverlight DataGrid中創建超鏈接列
- 4. HTML如何自動創建/以編程方式創建div?
- 5. Libgdx以編程方式創建序列動作
- 6. 如何以編程方式創建UIButton
- 7. 如何以編程方式創建GPO?
- 8. 如何以編程方式創建JPEG
- 9. 如何以編程方式創建DrawerLayout
- 10. 如何以編程方式創建NSPopover
- 11. 如何以編程方式創建SplitView?
- 12. 如何以編程方式創建Tabbar
- 13. 如何以編程方式創建UIViewController?
- 14. 如何以編程方式創建UISplitViewController?
- 15. 如何以編程方式創建CustomCell?
- 16. 如何以編程方式創建UIScrollView?
- 17. 如何以編程方式創建dojox.mobile.TabBar?
- 18. 如何以編程方式創建ProgressBar?
- 19. 如何以編程方式創建UIScrollview
- 20. 如何以編程方式創建UICollectionViewCell
- 21. 如何以編程方式創建NSFetchedPropertyDescription?
- 22. 如何以編程方式創建DSN?
- 23. 如何以編程方式創建BasicHttpBinding?
- 24. 如何以編程方式創建NSTextField?
- 25. 如何以編程方式創建dojo.mobile.view?
- 26. 如何以編程方式創建NSSearchField?
- 27. 如何以編程方式創建TextView?
- 28. Android創建列表以編程方式
- 29. 以編程方式/自動創建ViewControllers
- 30. 以編程方式創建框架的UIImage動畫