c# - Metro 应用程序的 C# Visual Studio 11 中的事件处理程序错误

标签 c# windows-8

我正在使用 VisualStudio 11 beta 进行 Windows 8 Metro 应用程序开发,但出现错误。 错误是:

Cannot implicitly convert type 
   'System.EventHandler<Windows.UI.Input.ManipulationStartedEventArgs>' to 
   'Windows.UI.Xaml.Input.ManipulationStartedEventHandler'

我的代码是。

selectRectangle.ManipulationStarted += new EventHandler<ManipulationStartedEventArgs>(OnRectangleManipulationStarted);
ellipseTL.ManipulationStarted += new EventHandler<ManipulationStartedEventArgs>(OnRectangleManipulationStarted);

最佳答案

我还没有使用 VS 2012 for Metro,但据我了解,Metro/.NET 4.5 对命名空间进行了一些重组,或者至少 selectRectangle/ellipseTL.ManipulationStarted 事件使用了不同的类。当然,在这种情况下,他们正在寻找 ManipulationStartedEventHandler不是EventHandler<> .

试试这个:

selectRectangle.ManipulationStarted += new Windows.UI.Xaml.Input.ManipulationStartedEventHandler(OnRectangleManipulationStarted);
ellipseTL.ManipulationStarted += new Windows.UI.Xaml.Input.ManipulationStartedEventHandler(OnRectangleManipulationStarted);

或者使用隐式事件处理程序语法:

selectRectangle.ManipulationStarted += OnRectangleManipulationStarted;
ellipseTL.ManipulationStarted += OnRectangleManipulationStarted;

但就像我说的,我还没有使用过新的 API,所以这只是我根据 4.0 的经验做出的最佳猜测。

编辑:您可能还需要更改 OnRectangleManipulationStarted 方法的签名以匹配 ManipulationStartedEventHandler 签名。

关于c# - Metro 应用程序的 C# Visual Studio 11 中的事件处理程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10499847/

相关文章:

c# - 将文本附加到文件 Windows 商店应用程序 (windows RT)

c# - 在新窗口中打开 excel 文件(即不是现有的 Excel 实例)

c# - 如何让安卓模拟器和微软视频一样快

c# - 在 Metro 应用程序中将 GridView 的每一列分配给不同的宽度

c# - Frame.Navigate() 与 this.Frame.Navigate()

c# - 布局类似于 Windows 8 中的天气应用程序

http - Windows 8 显然从压缩的 HTTP 响应中删除了内容编码 header

c# - 使用 Polly 重试之前正确的日志记录方法是什么

c# - 在 .NET 4.5 中编译的 LINQ 查询

c# - 优化自然排序序列的 Join、GroupBy、Distinct、Min/Max