我是Windows Phone动画的新手,并使用以下代码,但它给了我编译错误:‘System.Windows.Controls.Button’不包含’BeginAnimation’的定义,并且找不到扩展方法’BeginAnimation’接受类型为’System.Windows.Controls...

我是Windows Phone动画的新手,并使用以下代码,但它给了我编译错误:
‘System.Windows.Controls.Button’不包含’BeginAnimation’的定义,并且找不到扩展方法’BeginAnimation’接受类型为’System.Windows.Controls.Button’的第一个参数(您是否缺少using指令?或装配参考?)
我缺少哪个参考?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
private void button1_Click(object sender, RoutedEventArgs e)
{
DoubleAnimation da = new DoubleAnimation();
da.From = 30;
da.To = 100;
da.Duration = new Duration(TimeSpan.FromSeconds(1));
button1.BeginAnimation(Button.HeightProperty, da);
}
解决方法:
WP7中不存在UIElement.BeginAnimation方法.相反,您将需要创建一个故事板,如下所示:
private void button1_Click(object sender, RoutedEventArgs e)
{
var sb = new Storyboard();
var db = CreateDoubleAnimation(30, 100,
button1, Button.HeightProperty, TimeSpan.FromMilliseconds(1000));
sb.Children.Add(db);
sb.Begin();
}
private static DoubleAnimation CreateDoubleAnimation(double from, double to,
DependencyObject target, object propertyPath, TimeSpan duration)
{
var db = new DoubleAnimation();
db.To = to;
db.From = from;
db.Duration = duration;
Storyboard.SetTarget(db, target);
Storyboard.SetTargetProperty(db, new PropertyPath(propertyPath));
return db;
}
织梦狗教程
本文标题为:c#-在Windows Phone中的动画上编译错误


基础教程推荐
猜你喜欢
- C#中的类继承详解 2023-05-21
- c# – 基于asp.net mvc中的两个参数使用Linq-To-Sql进行分页 2023-11-10
- .net core系列之《将.net core应用部署到Ubuntu》 2023-09-28
- C#使用TimeSpan时间计算的简单实现 2022-12-26
- C#多线程系列之工作流实现 2023-05-21
- C#并行库Task类介绍 2023-06-15
- C#微信公众号开发之使用MessageHandler简化消息处理流程 2023-06-15
- C# 调用exe传参,并获取打印值的实例 2023-04-14
- C#基于百度AI实现机器翻译功能 2023-05-11
- C# 使用CancellationTokenSource取消多线程 2023-04-27