Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

how to show a usercontrol on MainWindow from another UserControl

$
0
0

I have two Usercontrol (CreationNouveauCas_uc and uc_TraiteTravail)and obviously one MainWindow and a grid inside it

<Grid x:Name="CreationNouveauCasGrid" HorizontalAlignment="Left" Height="653" Width="1170" Margin="137,30,0,0" VerticalAlignment="Top" />

I display the usercontrol CreationNouveauCas_uc on the MainWindow's Grid like this:

Private Sub btnShow_Click(sender As Object, e As RoutedEventArgs)
        Dim cnc As CreationNouveauCas_uc = New CreationNouveauCas_uc
        CreationNouveauCasGrid.Children.Clear()
        CreationNouveauCasGrid.Children.Add(cnc)
End Sub

so, I'm on the first UserControl (CreationNouveauCas_uc), and from it, I want to show the second usercontrol (uc_TT) on the same MainWindow's GridCreationNouveauCasGrid, So I do something like this

Private Sub btnShow_ucTT_Click(sender As Object, e As RoutedEventArgs)


  Dim mw As MainWindow = New MainWindow
  Dim uc_TT As ucTraiteTravail = New ucTraiteTravail                                        
  mw.CreationNouveauCasGrid.Children.Clear()                           
  mw.CreationNouveauCasGrid.Children.Add(uc_TT)
End Sub

And as I expected, it doesn't show anything.

but when I create a button on the MainWindow.xaml (it's to show the second userControl from the MainWindow) and apply this code-behind, it shows the userControl.

Private Sub btnShow_UserControl2_Click(sender As Object, e As RoutedEventArgs)
        Dim uc_TT As ucTraiteTravail = New ucTraiteTravail
        CreationNouveauCasGrid.Children.Clear()
        CreationNouveauCasGrid.Children.Add(uc_TT)
End Sub

so, here is the issue, how can I show the second user control on to the MainWindow's grid form the first usercontrol.

Any bit of possible solution is welcome



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>