我正在使用 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/