0

If the main WPF window creates a modeless window with no assigned owner, and then it creates a modal window, why does the modeless window get disabled? Here's a code snippet that illustrates the problem.

The 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" />

The code behind:

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();
        }
    }
}

Thanks!

Dale Barnard
  • 779
  • 1
  • 7
  • 16
  • Dale, I think your answer is found in this post. http://stackoverflow.com/questions/1111369/how-do-i-create-and-show-wpf-windows-on-separate-threads – JWP Dec 23 '15 at 16:38
  • 2
    I always thought that any modal window would disable _all_ other windows in the _same_ application, ie. this is how Windows works, the behaviour isn't different just because of WPF. Your "modeless" window is still part of your application, even if it does not have a "owner" window. – Steven Rands Dec 23 '15 at 16:51

0 Answers0