Hey all i am trying to add a label to my grid using the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim dynamicLabel As New Label()
Dim g As New Grid
dynamicLabel.Name = "NewLabel"
dynamicLabel.Content = "TEST"
dynamicLabel.Width = 240
dynamicLabel.Height = 30
dynamicLabel.Margin = New Thickness(0, 21, 0, 0)
dynamicLabel.Foreground = New SolidColorBrush(Colors.White)
dynamicLabel.Background = New SolidColorBrush(Colors.Black)
Grid.SetRow(dynamicLabel, 0)
Grid.SetColumn(dynamicLabel, 6)
g.Children.Add(dynamicLabel)
End Sub
However, i never see anything on the grid after i push the button... what am i missing?
In the shown code you never add the new grid to any window/control in a window.
I corrected this by naming the other grid. I never had the grid named and therefore thats why the .Children.Add never would add to the grid. I tried mainGrid.Children.Add (mainGrid is the name of my parent grid) and it would always throw an error because it was the grid inside that it was needing for this part.
gride is the name of my gride in dynamicForm.xaml window. it creates button and add to gride, then in button click evnt it creates a label by clicking on a the button.
If you need to add a button or a Label (just change Button to Label) to a Grid, you can use this:
and XAML