Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 552585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:30:55+00:00 2026-05-13T11:30:55+00:00

In a WPF application I would like to implement the following behaviour which doesn’t

  • 0

In a WPF application I would like to implement the following behaviour which doesn’t seem to work straightforward:

From the main window (Window1) the user opens a non-modal window (Window2), and that non-modal window may display a modal dialog (Window3).

The problem is that whenever the modal dialog has been shown, the main window disappears in the background (given that there are windows of other applications open) when the user closes the dialogs.

Is there anything wrong in the way that I use Window.Owner and Window.Show()/Window.ShowDialog(), is it a bug or is it something simply not supported?

The following simple WPF application demonstrates this behavior:

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

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Window2 win = new Window2();
        win.Owner = this;
        win.Show();
    }
}

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

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Window3 win = new Window3();
        win.Owner = this;
        win.ShowDialog();
    }

    private void btnClose_Click(object sender, RoutedEventArgs e)
    {
        this.Close();
    }
}

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

    private void btnClose_Click(object sender, RoutedEventArgs e)
    {
        this.Close();
    }
}

XAML Window1:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1">

    <Button Click="Button_Click">Show non-modal window</Button>
</Window>

XAML Window2:

<Window x:Class="WpfApplication1.Window2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window2">
    <StackPanel>
        <Button Click="Button_Click">Show modal dialog</Button>
        <Button Name="btnClose" Click="btnClose_Click">Close</Button>
    </StackPanel>
</Window>

XAML Window3:

<Window x:Class="WpfApplication1.Window3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window3">

    <Button Name="btnClose" Click="btnClose_Click">Close</Button>
</Window>

UPDATE: Fixed copy&paste error in the code. This is .NET 3.5 SP1 in case it matters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:30:56+00:00Added an answer on May 13, 2026 at 11:30 am

    Microsoft confirms this as a bug in WPF:

    This isn’t a regression from previous releases so it doesn’t make the bar to be fixed for this version of the product. We’ll look into this for a future release.

    In the meantime, this can be worked around by activating the owner window when the child window is closing.

    Sample code:

    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }
    
        private void NonModalButtonClick(object sender, RoutedEventArgs e)
        {
            new Window1 { Owner = this }.Show();
        }
    
        private void ModalButtonClick(object sender, RoutedEventArgs e)
        {
            new Window1 { Owner = this }.ShowDialog();
        }
    
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            if (this.Owner != null)
            {
                this.Owner.Activate();
            }
        }
    }
    

    (Note that the workaround will always bring the main window into foreground which might be different than the expected behavior)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 394k
  • Answers 395k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer IIRC the code is not Internals.pm but libinternals.c. It looks… May 15, 2026 at 2:31 am
  • Editorial Team
    Editorial Team added an answer Handle the parent window's unload event. May 15, 2026 at 2:31 am
  • Editorial Team
    Editorial Team added an answer If the map image is the only thing in the… May 15, 2026 at 2:31 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.