正在学习silverlight的游戏开发
第二讲书中代码实现了鼠标移动控件
联系题然我们自己实践用键盘移动
我编写的代码没有报错但是按下up键没有反应请大家帮我看下问题在哪里
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.Shapes;
namespace SilverlightApplication2
{
    public partial class MainPage : UserControl
    {
        Rectangle rectangle = new Rectangle()
        {
            Fill=new SolidColorBrush(Colors.Green),
            Width=50,
            Height=50
        };        public MainPage()
        {
            InitializeComponent();
            LayoutRoot.Children.Add(rectangle);
            LayoutRoot.MouseLeftButtonDown += new MouseButtonEventHandler(LayoutRoot_MouseLeftButtonDown);
            LayoutRoot.KeyDown += new KeyEventHandler(LayoutRoot_KeyDown);
        }        void LayoutRoot_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.PlatformKeyCode == ((int)Key.Up))
            {
                Point p = new Point();
                p.X = Canvas.GetLeft(rectangle);
                p.Y = Canvas.GetTop(rectangle);
                Storyboard storyboard = new Storyboard();
                DoubleAnimation upAnimation = new DoubleAnimation()
                {                    From = Canvas.GetTop(rectangle),
                    To = (p.Y - 100),
                    Duration = new Duration(TimeSpan.FromMilliseconds(50))                };
                Storyboard.SetTarget(upAnimation, rectangle);
                Storyboard.SetTargetProperty(upAnimation, new PropertyPath("(Canvas.Top)"));
                storyboard.Children.Add(upAnimation);
                storyboard.Begin();
                
            }
            
            
        }        void LayoutRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Point p = e.GetPosition(LayoutRoot);
            Storyboard storyboard = new Storyboard();
            DoubleAnimation xAnimation = new DoubleAnimation()
                {
                    From = Canvas.GetLeft(rectangle),
                    To = p.X,
                    Duration = new Duration(TimeSpan.FromMilliseconds(500))
                };
            Storyboard.SetTarget(xAnimation, rectangle);
            Storyboard.SetTargetProperty(xAnimation, new PropertyPath("(Canvas.Left)"));
            storyboard.Children.Add(xAnimation);            DoubleAnimation yAnimation = new DoubleAnimation()
            {
                From = Canvas.GetTop(rectangle),
                To = p.Y,
                Duration=new Duration(TimeSpan.FromMilliseconds(500))
            };
            Storyboard.SetTarget(yAnimation, rectangle);
            Storyboard.SetTargetProperty(yAnimation, new PropertyPath("(Canvas.Top)"));
            storyboard.Children.Add(yAnimation);
            storyboard.Begin();
        }           }
}