![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | 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 |
My System Specs![]() |
| | #2 (permalink) |
| | 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 |
My System Specs![]() |
| | #3 (permalink) |
| | 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 |
My System Specs![]() |