Solved

Parent WPF Window from a hosted usercontrol

Posted on 2014-03-12
6
1,166 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
  • 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now