Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

ウィンドウのモーダルとモードレスを検証する

MainWindow.xaml

<Window x:Class="HelloWorld.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">
    <StackPanel>
        <Button Click="ShowMethod">Show</Button>                <!-- モードレス -->
        <Button Click="UseVisibilityProperty">Visible</Button>  <!-- モードレス -->
        <Button Click="ShowDialogMethod">ShowDialog</Button>    <!-- モーダル -->
    </StackPanel>
</Window>

MainWindow.xaml.cs

using System.Windows;

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

        private void ShowMethod(object sender, RoutedEventArgs e) {
            Window w = new Window();
            w.Title = "Show";
            w.Height = 200;
            w.Width = 300;
            w.Show();
        }

        private void UseVisibilityProperty(object sender, RoutedEventArgs e) {
            Window w = new Window();
            w.Title = "Visiblity = Visible";
            w.Height = 200;
            w.Width = 300;
            w.Visibility = Visibility.Visible;
        }

        private void ShowDialogMethod(object sender, RoutedEventArgs e) {
            Window w = new Window();
            w.Title = "ShowDialog";
            w.Owner = this;
            w.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            w.ShowInTaskbar = false;
            w.Height = 200;
            w.Width = 300;
            w.ShowDialog();
        }
    }
}

アプリ実行