Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Getting the window which contains a usercontrol

 
 
Old 05-30-2007   #1 (permalink)
Michael Jackson


 
 

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 SpecsSystem Spec
Old 06-01-2007   #2 (permalink)
Laurent Bugnion, MVP


 
 

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 SpecsSystem Spec
Old 06-08-2007   #3 (permalink)
Andrew Whiddett \(Home\)


 
 

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 SpecsSystem Spec
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46