Child wpf window above parent window - wpf

I have WPF application with main window. I want to create child WPF window which always must be above ONLY parent window. If I set TopMost property for new window then window is above ALL nonTopMost windows on desktop. It's not what I want.

Set the Owner property of the child window so that it refers to the parent window.
child.Owner = parent;

Depending on the nature of the window, I often use a "Fake" window that is really just a layer in the parent along with a partailly transparent grey layer between that makes the parent look ghosted while the child is active. You can then keep the child window set to collapsed until it is needed.

Related

Paint child window that overflows outside top-level window

Is it possible to paint my child window that overflows outside its parent top-level window? I've seen combo-boxes can do this when their drop down is taller than the top-level window.
For example:
My window is a custom class with the style flags CS_HREDRAW | CS_VREDRAW. From what I understand I could use WS_EX_LAYERED? Or I could make the window taller and transparent to give the appearance of the window overflowing but those transparent areas either side of the red overflow are going to be Windows Message 'blackholes' that would really annoy the user if they click there expecting to be interacting with a different top-level window.
Is it possible to paint my child window that overflows outside its parent top-level window?
No. By definition, a child window
[...] is confined to the client area of its parent window.
But that's not what you need anyway. If you want to mimic the behavior of a combo box control, you need to create an owned pop-up window instead (see Owned Windows).

Who owns the process / main thread?

I created new WPF Application witn two windows.
MainWindow.xaml
Window1.xaml
Added one button in MainWindow.xaml and wrote the following code in the click event of the button:
Window1 w = new Window1();
w.Show();
I clicked that button 2-3 times and it opened multiple instances of Window1.
Everything fine till here.
Now, I closed MainWindow and it did not close the instances of Windows1.
I was thinking that since MainWindow is the one that owns the Process and if it closes, rest of the child windows will close automatically.
I did the same project in WinForms application and the result was completely different. On closing the MainWindow, it did close rest of the windows.
Am i not understanding the concept clearly? Can someone tell me who owns the process or the main thread in WPF?
The other windows are not child windows of your MainWindow unless you set window.Owner = mainWindow;
Further there is the Application.MainWindow property which sets which window actually is treated as "the" main window. This affects the Application.ShutdownMode if set to OnMainWindowClose.
Excerpt from the Window.Owner reference:
When a child window is opened by a parent window by calling ShowDialog, an implicit
relationship is established between both parent and child window. This relationship enforces certain behaviors, including with respect to minimizing, maximizing, and restoring.
When a child window is created by a
parent window by calling Show,
however, the child window does not
have a relationship with the parent
window. This means that:
The child window does not have a reference to the parent window.
The behavior of the child window is not dependent on the behavior of
the parent window; either window can
cover the other, or be minimized,
maximized, and restored independently
of the other.
To allow you to create a relationship
between a child window and a parent
window, Window supports the notion of
ownership. Ownership is established
when the Owner property of a window
(the owned window) is set with a
reference to another window (the owner
window).
The application root class: System.Windows.Application
WPF Threading Model

Get containt form patent window in child window

I want to create a child window in silverlight 4 but when the child window pop-up the parent window should not be disable.
I should able to access control or properties from parent window how do i do this.
Whether its possible?
Set OverlayBrush property of ChildWindow to transparent color
I think that you can find solution in FloatableWindow here.

How to stop WPF TopMost flag on parent window from being inherited by the child

I have a WPF window that has TopMost=true . When I call another Window from this window and specify the topmost window as the parent the owned window also displays as TopMost.
I would like to find a way to stop that from happening so that my parent can still own the child yet the child does not have TopMost=True.
I know I can just not bother to set the owner on the child then I won't get the TopMost flag, but I need all my windows to close with the parent window and writing the logic to handle that seems like a waste when it is included.
I've tried to explicitly set the TopMost=False after the child was loaded but no luck, it doesn't seem to matter if the owner window is TopMost then the child will be no matter what I do to it's TopMost property.
Any ideas?
Set The TopMost of the (parent) window, at runtime. (and not by default)

WPF Close UserControl in Frame and access Parent Controls

I have a WPF app with a Window (RootWindow) with a Toolbar and a Frame (ContentFrame). Initially the Toolbar is hidden.
I load a Login UserControl into the Frame and when the user correctly logs in I'd like to close the UserControl and then make the Parent Window toolbar visible.
Seems such a simple thing to do.
However, you cannot close a UserControl from within the UserControl. So how do I break out of the UserControl so I can remove it from the RootWindow (ContentFrame.Source=Nothing) and also make the toolbar Visible.
I can get a handle for the Parent Window with the following code but I cannot access the controls within it
Dim parentWindow As Window = Window.GetWindow(Me) 'Get a handle for parent window
Ideally, I'd like to be able to access Parent Window Controls from within a Child UserControl or at least be able to Trigger an event in the Parent Window from the Child UserControl.
To find the parent in the hirearchy you can use this code:
http://www.hardcodet.net/2009/03/detecting-double-click-events-on-the-wpf-datagrid
Although the problem solved in above article is for DataGrid, the code to find parent is generic enough and should work in your case.

Resources