Bringing modeless child dialog on top when parent dialog is clicked

I am developing an application in C# WPF .NET 3.5. I have a main window M, from which I open a modeless child window C1 with Owner property not set using Window.Show() method. From C1 window I create another child window C2. From C2 I create another child window C3. C2 and C3 are both modeless, created with Window.Show() method and with Owner property not set. Below is the sequence of windows:

M -> C1 -> C2 -> C3

I want the window behavior as follows. If C1 is clicked and if C2 is open, C2 is brought to top. If C2 is brought to top or if C2 is clicked and if C3 is open, C3 is brought to top. If M is clicked, then M should come to top. Thus C1, C2 and C3 would behave like modal windows. However I do not want C1, C2 and C3 to be actually modal i.e. I do not want to create them with Window.ShowDialog() method with Owner property set. This is because I want the user to be able to go to main window M if needed. How can I achieve this behavior?

I thank you in advance for your help.

geekowl

Update:

I added GotFocus event hander in the parent window as per suggestion, but GotFocus event does not get fired. So I added Activated event handler and in this handler called Activate() of the child window. This almost solved the problem, but under certain conditions this approach does not work perfectly. For example, when child is minimized and the parent is clicked, the child gets activated but the child does not get automatically maximized. I tried to bring the child to top using other methods instead of using Activate() but none of them gave a perfect solution. Ultimately, I used the method to hide the parent window after showing the child window and show the parent again when the child is closed.

Answers


You should be able to do this if you windows all have references to each other by using the Control.Focus() method.

You'd add an event handler to C1 that would call C2.Focus() when it is clicked. You'd do the same with C2 calling C3.Focus().

Based on what I'm gathering from your question, I think the best event for you to add a handler to would be the GotFocus event in your C1 and C2 windows. Basically, whenever they "gain focus", you would check to see if their child window is open, and then call Focus() on the child window. This would trigger GotFocus on that window (so if your user clicks on C1, it would bring C2 to the top, and then bring C3 to the top).


Need Your Help

How to resolve bootstrap not being applied on rails application developed on cloud9 ide?

ruby-on-rails ruby twitter-bootstrap cloud9-ide

I'm a beginner in developing applications using Ruby on Rails and I'm currently signed up and using Cloud9 as my development IDE.

How to make spydlay module to work like httplib/http.client?

python python-3.x spdy

I have to test server based on Jetty. This server can work with its own protocol, HTTP, HTTPS and lastly it started to support SPDY. I have some stress tests which are based on httplib /http.client...