Link to home
Start Free TrialLog in
Avatar of ymazal_ca
ymazal_ca

asked on

Parent WPF Window from a hosted usercontrol

Hi,
the situation is like this:
we have a method of a Facade (Controller) that gets a Winform User control has a parameter. The given user control is hosted in a wpf parent window.

In simple, if the user control was in the main window of the application, we have to close the MDI tab of that hosted this control.

If the control is from another window, that means that it is showen has a dialog and the parent window should close.

In simple, the question is, how do you get the parent window when you only have a winforms user control?

Would "ParentForm" work  ? but then you get a Form object that represent a Window ???
Or maybe "GetWindow" ? But then, since you don't have access to the host object, the Winform user control does not have any of this method... :P

Thank you!
Avatar of Ravi Vaddadi
Ravi Vaddadi
Flag of United States of America image

Is there any event on which you have to close the window
Avatar of ymazal_ca
ymazal_ca

ASKER

Its a generic fonction in a public [GOF] Facade that can be called from many different places.
I think I m lost.  did u say u r using q facade method to load that user control or r u saying u r calling a facade metho to close the parent window?  what triggers the closing of window
Its an application that has been developped for many years and now we are trying to transfer slowly to WPF.

There are many wiondows that are opened in a MDI style (in a devExpress Tab ).  The tab holds the hosted control in a WPF Host object that holds the Winform control.

Some times a control will be shown in a popup matter (all the same window).

In this architecture, we have a FacadeGui that has a method fncClose(Control p_Control), this Facade represent a [GRASP] controller of the Gui in general.

Anyway, in order to close a window, you call FacadeGui.getInstance().fncClose(aUserControl). In order to minimise coupling, the fncClose(...) methode does not know where the control came from and it needs to close the conained window (if its an MDI tab, then it needs to close that tab. If its a popup window, it needs to close that window).

Winform controls has the "ParentForm" property and the code can check if the given window is the main window application. In that case we check if the ParentForm is the main form and close the tab or the poup window other wise.

In simple, we have a winform user control in a host object in wpf and we need to find its WPF "window" to close it.
ASKER CERTIFIED SOLUTION
Avatar of ymazal_ca
ymazal_ca

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There was no other solutions and the question has been abandoned for more couple of days now.