“非数字”不是属性“From”的有效值 是什么意思

a6965921z 2010-02-06 09:05:00
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”的有效值
...全文
534 7 打赏 收藏 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
virusswb 2010-06-27
  • 打赏
  • 举报
回复
应该是类型赋值错误导致的。
应该赋值数值类型,可以你赋值了一个不是数值类型的值
  • 打赏
  • 举报
回复
这个错误是忘了设置图片的起始坐标Canvas.SetLeft(Spirit, 0);Canvas.SetTop(Spirit, 0)这样设置了就好了。
a6965921z 2010-02-08
  • 打赏
  • 举报
回复
学习了 原来按F11可以这样调试
jv9 2010-02-08
  • 打赏
  • 举报
回复
引用 3 楼 a6965921z 的回复:
引用 2 楼 jv9 的回复:
应该是你定义动画属性中,获取值的类型出现问题造成的错误提示,使用debug检查是哪段出现问题了。

怎么用debug 


在每个方法前设置断点,使用F11来逐步Debug
healer_kx 2010-02-07
  • 打赏
  • 举报
回复
UP,刚刚做了一个礼拜的Silverlight,感觉不错。
a6965921z 2010-02-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jv9 的回复:]
应该是你定义动画属性中,获取值的类型出现问题造成的错误提示,使用debug检查是哪段出现问题了。
[/Quote]
怎么用debug
jv9 2010-02-07
  • 打赏
  • 举报
回复
应该是你定义动画属性中,获取值的类型出现问题造成的错误提示,使用debug检查是哪段出现问题了。

8,757

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧