可以绕过ShowDialog()吗?

时间:2015-04-16 19:35:21

标签: c# wpf showdialog

我在使用我的项目时偶然发现了这个,但我能够在基础项目中重现这个:

我打开一个MainWindow,然后用ShowDialog一个子窗口,Owner设置为Main。当我点击Main时,Child开始闪烁,然后我开始在Main和Child之间快速点击,有时Main获得焦点,然后我可以打开另一个Child窗口。

主窗口:

<Window x:Class="WpfShowDialog.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="200" Width="300" WindowStartupLocation="CenterScreen" >
    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" >
        <TextBlock Text="MainWindow" Margin="10" />
        <Button Content="Open child" Margin="10" Click="Button_Click" />
    </StackPanel>
</Window>

代码背后:

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

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        var childWindow = new ChildWindow()
        {
            Owner = this
        };
        childWindow.ShowDialog();
    }
}

ChildWindow:

<Window x:Class="WpfShowDialog.ChildWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="ChildWindow" Height="150" Width="200" WindowStartupLocation="CenterOwner">
    <Grid>
        <TextBlock Text="ChildWindow" HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Grid>
</Window>

代码背后:

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

我在这些红色圆圈之间点击:

click locations

这是某种错误,还是我错过了什么?

0 个答案:

没有答案