c# - Silverlight new TouchPoint() 导致程序崩溃

标签 c# silverlight touch

我想在 Silverlight 中模拟 TouchPoint。以下代码已引发未处理的异常:

currentTouchPoints[i] = new TouchPoint();
currentTouchPoints[i].SetValue(TouchPoint.PositionProperty, 
   new Point(x[i]+100+i*100,y[i]+500));

第一次调用 new TouchPoint() 会使程序崩溃。

最佳答案

我想您可以调用新的 TouchPoint(),但是它的 TouchDevice 无效并且它的所有属性都是只读的,所以它没有用。

我自己还没有找到解决方案。

我会创建一个自定义类并改用它。

例如,如果您已经在代码中使用普通的 TouchPoint 并且不想更改所有内容,请导入此自定义命名空间而不是 System.Windows.Input

namespace MyTouchPoint 
{

class TouchPoint
{
public Point Position = new Point (0,0);
public TouchDevice TouchDevice = new TouchDevice();

TouchPoint (int id_, Point position_) 
{
    TouchDevice.Id = id_;
    Position = position_;
}
};

class TouchDevice
{
public int Id = 0;
};

} // end namespace

干杯, 洛伦佐

关于c# - Silverlight new TouchPoint() 导致程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8589830/

相关文章:

wpf - 数据模板中的数据绑定(bind)不起作用

jquery - 调整 Silverlight 容器 div 的大小会使 Silverlight 在 Firefox 中重新加载

javascript - Touch API(例如 touchstart)在 MS Edge 中不起作用

iphone - 触摸(点击)事件的顺序

c# - 流利的 NHibernate : mapping a dictionary of lists

c# - 在 WP7 中发出 http post 请求发送 JSON 文件

vb.net - Silverlight中的无效跨线程异常

c# - nm:共享库符号出现两次或一次

c# - SignalR - Multi-Tenancy 依赖注入(inject)

ios - Opengl Renderbuffer Texture touchmove ios 问题