C# 为什么模态WPF窗口禁用没有公共所有者的无模态窗口?

C# 为什么模态WPF窗口禁用没有公共所有者的无模态窗口?,c#,wpf,dialog,modal-dialog,modeless,C#,Wpf,Dialog,Modal Dialog,Modeless,如果主WPF窗口创建了一个没有指定所有者的无模式窗口,然后又创建了一个模式窗口,为什么会禁用无模式窗口?这里有一段代码片段说明了这个问题 xaml: <Window x:Class="ModalTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

如果主WPF窗口创建了一个没有指定所有者的无模式窗口,然后又创建了一个模式窗口,为什么会禁用无模式窗口?这里有一段代码片段说明了这个问题

xaml:

<Window x:Class="ModalTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Title="MainWindow">
    <Button Content="Show modal window" Click="buttonShowModalWindow_OnClick" />

谢谢

戴尔,我想你的答案可以在这篇文章中找到。我一直认为,任何模式窗口都会禁用同一应用程序中的所有其他窗口,也就是说,这就是windows的工作方式,行为不会因为WPF而有所不同。“无模式”窗口仍然是应用程序的一部分,即使它没有“所有者”窗口。
using System.Windows;
using System.Windows.Controls;
namespace ModalTest
{
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();

            var modelessWindowWithNoOwner = new Window { Content = new TextBlock { Text = "modeless window" } };
            modelessWindowWithNoOwner.Show();
        }

        private void buttonShowModalWindow_OnClick(object sender, RoutedEventArgs e)
        {
            var modalWindowWithOwner = new Window { Owner = this, Content = new TextBlock { Text = "modal window" } };
            modalWindowWithOwner.ShowDialog();
        }
    }
}