I'm stuck on this issue, please help.
I created an user control named "CreateNewCase_uc" within which I created a button Close named "btnClose"
In my MainWindow, I created a Grid named "grid1" and a button Open named "btnCreateNewCase" with this code
Private Sub btnCreateNewCase_Click(sender As Object, e As RoutedEventArgs) Dim cnc As CreateNewCase_uc = New CreateNewCase_uc grid1.Children.Clear() grid1.Children.Add(cnc) End Sub |
Thanks in advance for your help.
VulpesPosted Dec 15, 2013, 11:55 AM
VulpesPosted Dec 16, 2013, 6:16 AM
So the first thing we need to do to get back to the Grid is to convert the DependencyObject to Grid which is what CType(Me.Parent, Grid) does.
Having done that, then a reference to the UserControl will be held in the Grid's Children collection. I noticed that you'd cleared this collection before adding the UserControl and so the latter must be held at index 0 of the Children collection even if you've added further controls to the Grid.
So, having made sure that the Children collection hasn't been cleared in the meantime (its Count property is greater than zero), we just need to remove the item at index 0 of the collection which is what g.Children.RemoveAt(0) does.
William EKEPosted Dec 16, 2013, 2:52 AM