Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Getting the window which contains a usercontrol

Closed Thread
 
Thread Tools Display Modes
Old 05-30-2007   #1 (permalink)
Michael Jackson
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


Old 06-01-2007   #2 (permalink)
Laurent Bugnion, MVP
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
Old 06-08-2007   #3 (permalink)
Andrew Whiddett \(Home\)
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


Closed Thread

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








Vistax64.com 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 2005-2008

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 47 48 49 50