在我的MainWindow.xaml中,我有一个矩形。每当用户按住矩形上方的鼠标左键时,他就可以移动窗口。这是必需的,因为我使用的属性WindowStyle =“None”。
现在回答我的问题。如何从其他页面/类移动窗口?
我已经尝试将MainWindow的对象引用添加到页面中,但最终只是在StackOverflowException中。
MainWindow M_W = new MainWindow();
矩形的LeftMouseButtonDown事件:
private void Window_Move_Login(object sender, MouseButtonEventArgs e)
{
M_W.DragMove();
}
答案 0 :(得分:0)
您正在尝试实例化另一个MainWindow实例。请改用现有实例。
private void Window_Move_Login(object sender, MouseButtonEventArgs e)
{
Application.Current.MainWindow.DragMove();
}