“非数字”不是属性“From”的有效值 是什么意思
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Windows.Media.Animation;
namespace WpfApplication5
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
int count = 1;
Image Spirit;
Image map;
public Window1()
{
InitializeComponent();
intmap();
intplay();
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = TimeSpan.FromMilliseconds(150);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
Spirit.Source = new BitmapImage((new Uri(@"Player\" + count + ".png", UriKind.Relative)));
count = count == 7 ? 0 : count + 1;
}
private void intplay()
{
Spirit = new Image();
Spirit.Width = 150;
Spirit.Height = 150;
Carrier.Children.Add(Spirit);
}
private void intmap()
{
map = new Image();
map.Source = new BitmapImage((new Uri(@"Map\Map4.jpg", UriKind.Relative)));
map.Width = 800;
map.Height = 600;
Carrier.Children.Add(map);
}
private void Carrier_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Point p=e.GetPosition(Carrier);
Storyboard storyboard = new Storyboard();
//创建X动画
DoubleAnimation doubleAnimation = new DoubleAnimation(Canvas.GetLeft(Spirit), p.X, new Duration(TimeSpan.FromSeconds(1)));
Storyboard.SetTarget(doubleAnimation, Spirit);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Left)"));
//创建Y动画
storyboard.Children.Add(doubleAnimation);
doubleAnimation = new DoubleAnimation(Canvas.GetLeft(Spirit), p.Y, new Duration(TimeSpan.FromSeconds(1)));
Storyboard.SetTarget(doubleAnimation, Spirit);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Top)"));
storyboard.Children.Add(doubleAnimation);
//防如资源
if (!Resources.Contains("rectAnimation"))
{
Resources.Add("rectAnimation", storyboard);
}
storyboard.Begin();
}
}
}
当人物行走的时候会出现“非数字”不是属性“From”的有效值