Reputation: 3
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
My question : which Code I need to Write for my bntClose button which is inside the user control to close or make disappeared the user control in VB.NET
Thanks in advance for your help.
Upvotes: 0
Views: 1062
Reputation: 128013
You may simply set the UserControl's Visibility to Collapsed
:
Private Sub btnCreateNewCase_Click(sender As Object, e As RoutedEventArgs)
Me.Visibility = System.Windows.Visibility.Collapsed
End Sub
Upvotes: 1
Reputation: 9024
You need to get the Parent control then remove it.
' from inside your close button on UC.
Dim parent = TryCast(Me.Parent, Grid))
If Not parent Is Nothing Then
parent.Children.Remove(Me)
End If
Upvotes: 2