Solved

Parent WPF Window from a hosted usercontrol

Posted on 2014-03-12
6
1,275 Views
Last Modified: 2014-03-23
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
Comment
Question by:ymazal_ca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 39927951
Is there any event on which you have to close the window
0
 

Author Comment

by:ymazal_ca
ID: 39928162
Its a generic fonction in a public [GOF] Facade that can be called from many different places.
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 39928185
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:ymazal_ca
ID: 39928220
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
 

Accepted Solution

by:
ymazal_ca earned 0 total points
ID: 39937866
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
 

Author Closing Comment

by:ymazal_ca
ID: 39948412
There was no other solutions and the question has been abandoned for more couple of days now.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question