我是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# – 使用Windows 10 Universal App的iTextSharp 2023-09-18
- C# DirectShow预览摄像头并截图 2023-04-27
- C#实现递归调用的Lambda表达式 2023-06-15
- c# – SQL唯一键插入 2023-11-26
- Unity实战之FlyPin(见缝插针)小游戏的实现 2023-05-12
- c# 获得当前绝对路径的方法(超简单) 2022-12-06
- C#栈和队列的简介,算法与应用简单实例 2023-01-06
- C# 操作Windows注册表的实现方法 2023-05-26
- c# – linux / mono上的HTTP性能 2023-09-19
- C#微信公众号开发之用户上下文WeixinContext和MessageContext 2023-06-15