メインの 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" />
背後にあるコード:
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();
}
}
}
ありがとう!