在 LostFocus 之后关闭 ContentDialog,然后单击 MainPage Interface

close a ContentDialog after LostFocus on it and click on the MainPage Interface

我已经使用 ContentDialog 创建了一个 PopUp ContentDialog,就像 Groove App 中的那样:

问题是,当我点击 MainPage 界面的任何部分并失去焦点时,我无法关闭它,我试过这样,但它不起作用:(,它只在我之后关闭从 ContentDialog

发送数据

MainPage.xaml:

private void MenuButton_Click(object sender, RoutedEventArgs e)
    {

            AddFavoris formTask = new AddFavoris();
            t = formTask.ShowAsync();
            string f = formTask.Opgave;
            formTask.LostFocus += new RoutedEventHandler(formTask_LostFocus);

       }


private void formTask_LostFocus(object sender, RoutedEventArgs e)
        {
            t.Cancel();
        }

所以,有没有什么解决方案可以让我使用一个 ContrentDialog,它会在单击 MainPage 界面并失去对它的关注后关闭 感谢帮助

使用 Flyout 而不是使用 ContentDialog。可以通过点击或单击弹出窗口外的某处来关闭弹出窗口。

更多信息:Guidelines for flyouts, Guidelines for dialog controls