我有一个带有.NET-4.5的WPF画布。
我添加了事件(为其自动创建方法) MouseLeftButtonDown和MouseDown。使用MessageBox,我已经确认当用户在画布上单击时会调用这些方法,但我找不到从MouseButtonEventArgs获取鼠标位置的方法。
当我为ManipulationStarted和ManipulationStarting添加事件(以及自动创建的方法)时,这些MessageBoxes不会出现。
private void CenterCanvas_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
MessageBox.Show("Doesn't show up"); // never shows up
}
private void CenterCanvas_MouseDown(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("Shows up"); // shows up, but can't seem to get click position
}发布于 2013-01-10 16:11:44
为了从MouseEventArgs获取鼠标位置,您必须调用GetPosition方法。
private void Canvas_MouseDown(object sender, MouseButtonEventArgs e)
{
var pos = e.GetPosition((IInputElement)sender);
System.Diagnostics.Trace.TraceInformation("MouseDown at {0}", pos);
}要获取操作事件,需要将IsManipulationEnabled设置为true。您可能想看看MSDN Input Overview中的Touch and Manipulation部分。
https://stackoverflow.com/questions/14250165
复制相似问题