简体   繁体   English

用户尝试触摸过去的屏幕时如何关闭WPF对话框窗口

[英]how to close a WPF Dialog Window when user try to touch past window screen

Please look at image, 请看图片,

在此处输入图片说明

It has two windows, red one opens after green one. 它有两个窗口,红色一个在绿色一个之后打开。

How could I close red windows when user touch green screen ? 用户触摸绿屏时如何关闭红色窗口?

Also I have using 我也用

protected override void OnDeactivated(EventArgs e)
{
    base.OnDeactivated(e);
    Close();
}

But this works only when user open another application 但这仅在用户打开另一个应用程序时有效

here is my green window code, that opens red window 这是我的绿色窗口代码,打开红色窗口

MainWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
           Window1 w=new Window1();
            w.ShowDialog();
        }

I cannot give you a direct answer since I do not do WPF programming, but an approach I use on IOS is to have one big form, the outer part is transparent and it actually contains one huge button, which is also transparent, only the Window1 is visible. 我不给您直接的答案,因为我不进行WPF编程,但是我在IOS上使用的一种方法是采用一种较大的形式,外部是透明的,并且实际上包含一个巨大的按钮,该按钮也是透明的,只有Window1是可见的。 On the button press event close window1. 在按钮上按事件关闭窗口1。

But I am pretty sure you should have a way to detect click events on the green part and then close the window1. 但是我很确定您应该有一种方法可以检测绿色部分上的单击事件,然后关闭window1。 Maybe add some event listener to some component you place on the green part. 也许将一些事件侦听器添加到放置在绿色部分上的某些组件中。

See this answer: how to close a WPF Dialog Window when the user clicks outside it 看到此答案: 用户在窗口外单击时如何关闭WPF对话框窗口

Here is a answer I copied: 这是我复制的答案:

public partial class MainWindow : Window
{
public MainWindow()
{
    InitializeComponent();
}

protected override void OnDeactivated(EventArgs e)
{
    base.OnDeactivated(e);
    Close();
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM