我有一个带有 StackPanel 作为 ListView 项的 ListView。 StackPanel 有一个右键单击时显示的上下文菜单。我可以使用拖放操作重新排列 StackPanel 顺序。
问题是,当我选择并右键单击显示的 StackPanel (ListViewItem) 上下文菜单时,然后我单击另一个 StackPanel(其他 ListViewItem),DragEnter、DragOver 和 DragLeave 事件被触发。
简单的右击和左击操作被解释为拖放。我尝试将鼠标右键 Up 和 Down 事件设置为 handled true 但没有用。 如何区分这种情况与真正的拖放操作?
最佳答案
如果您还没有这样做……您可以将初始鼠标位置存储在 PreviewMouseLeftButtonDown 上,并使用 PreviewMouseMove 来确定用户是否正在进行拖放操作。下面是一些示例代码:
private static void OnPreviewMouseLeftButtonDown( object sender, MouseButtonEventArgs e )
{
// Store the mouse position
m_StartPoint = e.GetPosition( null );
}
和
private static void OnPreviewMouseMove( object sender, MouseEventArgs e )
{
Point mousePos = e.GetPosition( null );
Vector diff = m_StartPoint - mousePos;
if ( e.LeftButton == MouseButtonState.Pressed &&
( Math.Abs( diff.X ) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs( diff.Y ) > SystemParameters.MinimumVerticalDragDistance ) )
{
// Dragging ...
}
}
https://stackoverflow.com/questions/31544638/
相关文章:
cmake - 带有特殊字符的 custom_command ECHO
javascript - 使用 python 电子邮件或其他模块在电子邮件中发送 Bokeh 图
r - 如何计算 vowpal wabbit 中 LDA 模型的对数似然
android - AlertDialog 内的 DatePickerDialog(在特定的 Edi
java - 如何通过键前缀查询 Samza KeyValueStore?
sql - 如何在 SQL MS Access 2013 中根据文本特征标准和 n+1、n+2、n+
php - 使用 Jsonb 绑定(bind)参数?|使用 Postgres 的 Doctrine2
asp.net - executionTimeout 发送响应