我有一个应用程序,我想移动窗口的问题是所有现在有预览鼠标的图像都无效。
这是windo事件:
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
这是图像事件:
private void image1_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("WTF IS WPF?");
}
如果我删除了DragMove函数,则图像事件可以正常工作。
答案 0 :(得分:3)
为什么一直执行DragMove()?
MouseButtonState _mouseButtonState;
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
_mouseButtonState = e.ButtonState;
}
private void Window_MouseMove(object sender, MouseEventArgs e)
{
if(_mouseButtonState == MouseButtonState.Pressed)
DragMove();
}
我还会检查image1_PreviewMouseUp
private void image1_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if(_dragging) return;
//else do your preview
}