2012-03-13 106 views
3

我是新的Windows手機動畫和使用下面的代碼,但它給我的編譯錯誤:編譯錯誤的Windows Phone

「System.Windows.Controls.Button」不包含「BeginAnimation的定義'並沒有擴展方法'BeginAnimation'接受類型'System.Windows.Controls.Button'的第一個參數可以找到(你是否缺少使用指令或程序集引用?)

我缺少哪個引用?

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);    
    } 
+0

WP7!= WPF。你在使用哪一個? – SLaks 2012-03-13 01:39:33

+0

@SLaks VS2010 WP7.1 – user1222006 2012-03-13 01:43:12

+1

Windows Phone並不是WPF。 – SLaks 2012-03-13 01:43:45

回答

3

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; 
}