答案 0 :(得分:2)
看看这是否是您想要的,我使用了StackPanel's
和DockPanel
,这会随着内容的添加而增加,我还添加了5个额外TextBox's
和{{1}具有折叠的可见性,这意味着它们在不可见时不会占用任何空间。我将它们添加到List中,然后在您单击按钮时检查可见性,使当时可以看到相应的控件。
<强> MainWindow.xaml 强>
TextBlock's
<强> MainWindow.xaml.cs 强>
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="214" Width="525" SizeToContent="WidthAndHeight">
<Grid>
<GroupBox Header="General Information" HorizontalAlignment="Left" Name="groupBox1" VerticalAlignment="Top">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="0" HorizontalAlignment="Left" >
<Button VerticalAlignment="Bottom" Height="25" Click="Button_Click" >Add</Button>
</DockPanel>
<StackPanel Name="stackpanelTB" Grid.Column="1" Orientation="Vertical" >
<StackPanel.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="0,4,0,0"/>
</Style>
</StackPanel.Resources>
<TextBox Name="textBox1" Width="240" Height="25"></TextBox>
<TextBox Name="textBox2" Width="240" Height="25"></TextBox>
<TextBox Name="textBox3" Width="240" Height="25"></TextBox>
<TextBox Name="textBox4" Width="240" Height="25"></TextBox>
<TextBox Name="textBox5" Width="240" Visibility="Collapsed" Height="25"></TextBox>
<TextBox Name="textBox6" Width="240" Visibility="Collapsed" Height="25"></TextBox>
<TextBox Name="textBox7" Width="240" Visibility="Collapsed" Height="25"></TextBox>
<TextBox Name="textBox8" Width="240" Visibility="Collapsed" Height="25"></TextBox>
<TextBox Name="textBox9" Width="240" Visibility="Collapsed" Height="25"></TextBox>
</StackPanel>
<StackPanel Name ="stackpanelCaption" Grid.Column="2" Orientation="Vertical">
<StackPanel.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="0,4,0,0"/>
</Style>
</StackPanel.Resources>
<TextBlock Name="textBlock1" HorizontalAlignment="Right" Height="25">Ingredient ID</TextBlock>
<TextBlock Name="textBlock2" HorizontalAlignment="Right" Height="25">Ingredient Name</TextBlock>
<TextBlock Name="textBlock3" HorizontalAlignment="Right" Height="25">Chemical Str</TextBlock>
<TextBlock Name="textBlock4" HorizontalAlignment="Right" Height="25">Ingredient Salts</TextBlock>
<TextBlock Name="textBlock5" HorizontalAlignment="Right" Visibility="Collapsed" Height="25"></TextBlock>
<TextBlock Name="textBlock6" HorizontalAlignment="Right" Visibility="Collapsed" Height="25"></TextBlock>
<TextBlock Name="textBlock7" HorizontalAlignment="Right" Visibility="Collapsed" Height="25"></TextBlock>
<TextBlock Name="textBlock8" HorizontalAlignment="Right" Visibility="Collapsed" Height="25"></TextBlock>
<TextBlock Name="textBlock9" HorizontalAlignment="Right" Visibility="Collapsed" Height="25"></TextBlock>
</StackPanel>
</Grid>
</GroupBox>
</Grid>
</Window>