• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1438
  • Last Modified:

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!
0
ymazal_ca
Asked:
ymazal_ca
  • 4
  • 2
1 Solution
 
SriVaddadiCommented:
Is there any event on which you have to close the window
0
 
ymazal_caAuthor Commented:
Its a generic fonction in a public [GOF] Facade that can be called from many different places.
0
 
SriVaddadiCommented:
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
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
ymazal_caAuthor Commented:
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.
0
 
ymazal_caAuthor Commented:
Here is what was done:
in the Application class, there is all the list of windows. when the control is send to the Facade, each window is examined if he has a host that hold this control.

If its the main window, then the list of tabs (mdi windows in Tabs) was examin and the proper tab was closed. To bad you can't just get the window directly from the winform control in WPF...
0
 
ymazal_caAuthor Commented:
There was no other solutions and the question has been abandoned for more couple of days now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now