![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Getting the window which contains a usercontrol I have a user control hosted on a Window. The user control is actually within a grid which is within a border. When I call MessageBox.Show, from a button on the user control, the first parameter I want to pass is 'owner'. How can I determine the "winodw" that the user control is on. Is there a property of UserControl? Thanks, Michael |
| | #2 (permalink) |
| Guest | Re: Getting the window which contains a usercontrol Hi, Michael Jackson wrote: > I have a user control hosted on a Window. The user control is actually > within a grid which is within a border. > > When I call MessageBox.Show, from a button on the user control, the first > parameter I want to pass is 'owner'. How can I determine the "winodw" that > the user control is on. Is there a property of UserControl? > > Thanks, > Michael You can navigate the logical tree using the Control class' "Parent" property. This will allow you to retrieve the top window quite easily (for example, get the parent recursively until you find one of type "Window".) Also, the LogicalTreeHelper class has static methods to help you navigate this tree, but it doesn't bring much more in your case than the "Parent" property. You can also get the main window from everywhere in your application using App.Current.MainWindow. However, if you have multiple windows, this may not be the right one. HTH, Laurent -- Laurent Bugnion [MVP ASP.NET] Software engineering, Blog: http://www.galasoft-LB.ch PhotoAlbum: http://www.galasoft-LB.ch/pictures Support children in Calcutta: http://www.calcutta-espoir.ch |
| | #3 (permalink) |
| Guest | Re: Getting the window which contains a usercontrol If you pick up my library at : http://blogs.msdn.com/karstenj/archi...19/579233.aspx All you need to do is: FrameworkElement fe = BaseWPFHelpers.Helpers.SingleFindInTree(mysender, new FinderMatchType(typeof(Window))); if(fe != null) { } "Laurent Bugnion, MVP" <galasoft-lb@bluewin.ch> wrote in message news:OJb5eWCpHHA.2156@TK2MSFTNGP03.phx.gbl... > Hi, > > Michael Jackson wrote: >> I have a user control hosted on a Window. The user control is actually >> within a grid which is within a border. >> >> When I call MessageBox.Show, from a button on the user control, the first >> parameter I want to pass is 'owner'. How can I determine the "winodw" >> that the user control is on. Is there a property of UserControl? >> >> Thanks, >> Michael > > You can navigate the logical tree using the Control class' "Parent" > property. This will allow you to retrieve the top window quite easily (for > example, get the parent recursively until you find one of type "Window".) > Also, the LogicalTreeHelper class has static methods to help you navigate > this tree, but it doesn't bring much more in your case than the "Parent" > property. > > You can also get the main window from everywhere in your application using > App.Current.MainWindow. However, if you have multiple windows, this may > not be the right one. > > HTH, > Laurent > -- > Laurent Bugnion [MVP ASP.NET] > Software engineering, Blog: http://www.galasoft-LB.ch > PhotoAlbum: http://www.galasoft-LB.ch/pictures > Support children in Calcutta: http://www.calcutta-espoir.ch |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Drawing Polygon on UserControl | Sudha | Avalon | 1 | 02-21-2008 11:02 AM |
| UserControl inside another UserControl with WYSIWYG | jan.bannister@gmail.com | Avalon | 1 | 02-07-2007 06:42 AM |
| How to bind to a usercontrol property from inside this usercontrol | Pon | Avalon | 4 | 11-13-2006 08:38 AM |
| UserControl in VB project | Eli | Avalon | 1 | 06-05-2006 06:25 PM |
| WPF UserControl in a Forms.UserControl | MichaelG | Avalon | 2 | 01-10-2006 03:52 PM |