当 showdialogwindow 阻止我尝试访问的窗口时,是否有事件或我可以使用的东西 [英] Is there an event or something i can use when a showdialogwindow is blocking the window i try to access

查看:14
本文介绍了当 showdialogwindow 阻止我尝试访问的窗口时,是否有事件或我可以使用的东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个窗户.让我们称他们为 A 和 B.A 正在使用 ShowDialog() 打开 B.所以我打开 B - 当用户最小化 B 或以某种方式将其放入后面,并且他尝试再次单击窗口 A 时,它被阻止(应该是这样),但是当发生这种情况时,我是否可以赶上事件?

I have 2 windows. Lets call them A and B. A is opening B with a ShowDialog(). So I am opening B - When the user minimizes B or gets it into the back somehow and he tries clicking window A again its blocked (as it should be), but is there an Event that I can catch up onto when this happens ?

当他试图在打开窗口 B 的情况下访问窗口 A 时,我试图实现将阻塞窗口 B 带到前面.

I am trying to achieve bringing the blocking window B into the front when hes trying to access window A with window B opened.

代码示例:

这就是从主窗口打开窗口 A 的方式

Thats how Window A is opened from the Mainwindow

            WindowA windowA = new WindowA();

            windowA.Owner = Application.Current.MainWindow;

            windowA.Show();
            windowA.Activate();

窗口B就是这样打开的

            WindowB windowB = new WindowB();
            windowB.Owner = this; //(this = windowA)
            windowB.ShowDialog();

两个窗口都没有设置特殊的属性,除了

Both windows have no special properties set except

WindowStartupLocation="CenterScreen"

推荐答案

如果你想在第二个窗口最小化时恢复第二个窗口并且用户确实点击了第一个(被阻止的)窗口,那么你可以这样做(将此代码添加到WindowB):

If you want to restore second window when it is minimized and user does click on first(blocked) window, then you can go this way(add this code to the WindowB):

public WindowB()
{
    PreviewMouseDown += WindowB_PreviewMouseDown;
    StateChanged += WindowB_StateChanged;
    InitializeComponent();
    LostMouseCapture += WindowB_LostMouseCapture;

}

private void WindowB_LostMouseCapture(object sender, MouseEventArgs e)
{
    //You can also evaluate here a mouse coordinates.
    if (WindowState == WindowState.Minimized)
    {
        e.Handled = true;
        CaptureMouse();
    }
}

private void WindowB_StateChanged(object sender, EventArgs e)
{
    if (WindowState== WindowState.Minimized)
    {
        CaptureMouse();
    }
    else
    {
        ReleaseMouseCapture();
    }
}

private void WindowB_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
    WindowState = WindowState.Normal;
    Debug.WriteLine("WindowB PreviewMouseDown");
}

因此,您必须在最小化的第二个窗口上开始鼠标捕获,因为如果用户确实单击了 WindowA,这可以在 WindowB 上处理.
当窗口最小化时,它会丢失鼠标捕获(因此您必须监听 LostMouseCapture),您必须防止这种情况.

So you have to start mouse capturing on second window on it being minimized, for if user does click on WindowA this can be handled on WindowB.
As window being minimized it going to lost a mouse capture(therefore you have to listen on LostMouseCapture), that you have to prevent.

WindowA 上按下鼠标左键会恢复然后WindowB.

Left mouse button down on WindowA does restore thenWindowB.

这篇关于当 showdialogwindow 阻止我尝试访问的窗口时,是否有事件或我可以使用的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆