UserControlsHi<br><br>I have a window with a btnLoadUC and canvas where i add the usercontrol's children.<br><br>        Dim uc As New myUserControl<br>        Canvas.Children.Add(uc)<br><br>Works fine<br><br>now in my usercontrol i have a close button , so how do i call the parent control to remove the uc from the<br>canvas?<br><br>Thanks<br><br><br><br><br><br> © 2009 Microsoft Corporation. All rights reserved.Thu, 24 Jul 2008 19:28:04 Z5ffceb21-7888-4333-abd8-16828a5cdacbhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5ffceb21-7888-4333-abd8-16828a5cdacb#5ffceb21-7888-4333-abd8-16828a5cdacbhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5ffceb21-7888-4333-abd8-16828a5cdacb#5ffceb21-7888-4333-abd8-16828a5cdacbvbturbohttp://social.msdn.microsoft.com/Profile/en-US/?user=vbturboUserControlsHi<br><br>I have a window with a btnLoadUC and canvas where i add the usercontrol's children.<br><br>        Dim uc As New myUserControl<br>        Canvas.Children.Add(uc)<br><br>Works fine<br><br>now in my usercontrol i have a close button , so how do i call the parent control to remove the uc from the<br>canvas?<br><br>Thanks<br><br><br><br><br><br> Thu, 24 Jul 2008 10:42:45 Z2008-07-24T10:42:45Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5ffceb21-7888-4333-abd8-16828a5cdacb#b559336d-c3bf-4240-b015-ed903aa42951http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5ffceb21-7888-4333-abd8-16828a5cdacb#b559336d-c3bf-4240-b015-ed903aa42951Bragihttp://social.msdn.microsoft.com/Profile/en-US/?user=BragiUserControlsFrom your usercontrol, you can get the visual parent, which is the canvas you put it in.  To get the visual parent, use:<br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px">VisualTreeHelper.GetParent(this); </font></td></tr></tbody></table></div>VisualTreeHelper is a helper class that allows you to walk the visual tree.  The visual tree is a tree built up of UI elements, ordered in the way that they are currently visible (rendered).  You also have the logicalTree, which represents the tree structure of your xaml (this can be different from the visual tree).<br> Thu, 24 Jul 2008 15:13:41 Z2008-07-24T15:13:41Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5ffceb21-7888-4333-abd8-16828a5cdacb#51a1bc68-2b21-4eff-8180-dbad68026676http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5ffceb21-7888-4333-abd8-16828a5cdacb#51a1bc68-2b21-4eff-8180-dbad68026676vbturbohttp://social.msdn.microsoft.com/Profile/en-US/?user=vbturboUserControlsHi Bragi<br><br>Thanks for reply.<br>Yes im now able to get the parent control.<br>Though is there an easier way to unload the control from it self ? <br><br>like this in my control    this.close();<br><br>Thanks<br> Thu, 24 Jul 2008 18:05:59 Z2008-07-24T18:05:59Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5ffceb21-7888-4333-abd8-16828a5cdacb#f23282b3-7181-4acc-96b3-1d0bd4e4348chttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5ffceb21-7888-4333-abd8-16828a5cdacb#f23282b3-7181-4acc-96b3-1d0bd4e4348cBragihttp://social.msdn.microsoft.com/Profile/en-US/?user=BragiUserControls No there isn't.  here's the problem: a UserControl can visually be 'owned' by any number of different controls: it could be the Content of a Button, Popup, MenuItem, it could be put on a ToolBar, a Panel, in the template of an itemscontrol.  Sometimes it could close, sometimes it can't.  You should try to look at it from the other side of the equation: if you need to manage several objects on a canvas that need to be dynamically added and removed, use an ItemsControl instead.  Bind this to an observable collection that contains your userControls (or better: an observableCollection that contains data objects + use a DataTemplate that contains your userControl). If you add and remove items from this list, it will automatically be updated in your listbox.  To use a canvas instead of a StackPanel, change the ItemsPanelTemplate property of the ItemsControl and assign it a Canvas.<br>To correctly set Canvas.Left, .... you should assign an ItemContainerStyle to the ItemsControl which should create a binding between the Canvas.XXX properties and your Data properties.<br>Hope this helps.<hr size="1" align="left" width="25%">BragiThu, 24 Jul 2008 18:15:18 Z2008-07-24T18:15:18Z