Hey all i am trying to add a label to my grid using the following code:
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
My WPF code is this:
Code:
<Window x:Class="msgWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="msgWindow" Height="110" Width="930"
WindowStyle="None" AllowsTransparency="True" Background="Transparent"
ShowInTaskbar="False" Topmost="True" BorderThickness="1" BorderBrush="Black"
Focusable="False" ShowActivated="False" Opacity="1">
<Grid Width="930" Opacity="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="778*" />
</Grid.ColumnDefinitions>
<Label Background="#FFCDCDE5" Content="ID" FontFamily="Arial" FontSize="9" Height="20" HorizontalAlignment="Left" Name="Label1" VerticalAlignment="Top" Width="58" Foreground="White" Margin="0,0,0,0" />
<Label Background="#FFCDCDE5" Content="Status" FontFamily="Arial" FontSize="9" Height="20" HorizontalAlignment="Left" Name="Label2" Margin="60,0,0,0" VerticalAlignment="Top" Width="76" Foreground="White" />
<Label Background="#FFCDCDE5" Content="Priority" FontFamily="Arial" FontSize="9" Height="20" HorizontalAlignment="Left" Name="Label3" VerticalAlignment="Top" Width="53" Grid.Column="1" Margin="2,0,0,0" Foreground="White" />
<Label Background="#FFCDCDE5" Content="Title" FontFamily="Arial" FontSize="9" Height="20" HorizontalAlignment="Left" Name="Label4" Margin="57,0,0,0" VerticalAlignment="Top" Width="310" Grid.Column="1" Foreground="White" />
<Label Background="#FFCDCDE5" Content="Expire" FontFamily="Arial" FontSize="9" Height="20" HorizontalAlignment="Left" Name="Label5" Margin="369,0,0,0" VerticalAlignment="Top" Width="113" Grid.Column="1" Foreground="White" />
<Label Background="#FFCDCDE5" Content="Date" FontFamily="Arial" FontSize="9" Height="20" HorizontalAlignment="Left" Name="Label6" Margin="484,0,0,0" VerticalAlignment="Top" Width="122" Grid.Column="1" Foreground="White" />
<Label Background="#FFCDCDE5" Content="Assigned" FontFamily="Arial" FontSize="9" Height="20" HorizontalAlignment="Left" Name="Label7" Margin="608,0,0,0" VerticalAlignment="Top" Width="183" Grid.Column="1" Foreground="White" />
<Label Background="Red" Content="X" FontFamily="SansSerif" FontSize="9" Height="20" HorizontalAlignment="Left" Margin="777,0,0,0" Name="Label8" VerticalAlignment="Top" Width="16" Grid.Column="1" Foreground="White" />
<Button Content="Button" Grid.Column="1" Height="27" HorizontalAlignment="Left" Margin="35,30,0,0" Name="Button1" VerticalAlignment="Top" Width="74" />
</Grid>
</Window>
However, i never see anything on the grid after i push the button... what am i missing?