Reputation: 79
My code on the xaml looks something like this
</Grid>
<Grid Grid.Column="1" Grid.Row="0" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="*" ></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Center" Content="Updates Avalable"></Label>
<Button Name="btnUpdate" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Center" MouseDoubleClick="btnUpdate_MouseDoubleClick" >Check For Available Updates</Button>
<StackPanel Name="controlHolder" Grid.Column="0" Grid.Row="1">
</StackPanel>
</Grid>
Then i create a custom control and try adding it to the stackPanel like this
File_Type_Control_Green ftcg = ftc.GeneratefileTypeControl("file", "hello", "3mb", "someurl", "2-3-4");
controlHolder.Children.Add(ftcg);
However, when i do that it literally puts it inside the button.
In windows forms you can just add controls to panel no problem but it seems to be a big problem in wpf. I don't know how to go about fixing this. Can someone point me in the right direction?
main goal is to add the new controls dynamically to the stack panel. I haven't done it yet, but i will add xy locations to space the controls out properly assuming you can do that like in panel.
Thanks!
Upvotes: 0
Views: 31
Reputation: 20046
You had both Button and StackPanel filling up the same grid cell(Grid.Column="0" Grid.Row="1"). The StackPanel has a higher Z-Index but it has transparent background by default, and you may not visually tell them apart as they overlaps. Perhaps you can wrap both your Button and StackPanel into a another StackPanel.
<Grid Grid.Column="1" Grid.Row="0" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="*" ></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Center" Content="Updates Avalable"></Label>
<StackPanel Grid.Column="0" Grid.Row="1" Orientation="Vertical">
<Button Name="btnUpdate" />
<StackPanel Name="controlHolder" />
</StackPanel>
</Grid>
Upvotes: 2