我正在尝试使用 WPF 布局,但我对如何让某些东西起作用感到困惑。我希望我DockPanel
根据标签的大小自动调整大小。现在,我发现了如何让Labels
它们自己自动调整大小,但它不会改变StackPanel
or的宽度DockPanel
。这是我的 XAML:
<Grid>
<DockPanel Margin="0,0,687,340" Width="Auto" LastChildFill="False">
<StackPanel DockPanel.Dock="Left" Width="Auto" Height="Auto">
<Label Content="Job #" Height="Auto" Margin="0,5" Name="label1" Style="{StaticResource MyLabel2}" Width="Auto" HorizontalContentAlignment="Right" />
<Label Content="Customer" Height="Auto" Margin="0,5" Name="label2" Style="{StaticResource MyLabel2}" Width="Auto" HorizontalContentAlignment="Right" />
<Label Content="Location" Height="Auto" Margin="0,5" Name="label3" Style="{StaticResource MyLabel2}" Width="Auto" HorizontalContentAlignment="Right" />
<Label Content="Crossing" Height="Auto" Margin="0,5" Name="label4" Style="{StaticResource MyLabel2}" Width="Auto" HorizontalContentAlignment="Right" />
<Label Content="Engineer" Height="Auto" Margin="0,5" Name="label5" Style="{StaticResource MyLabel2}" Width="Auto" HorizontalContentAlignment="Right" />
<Label Content="Probe #" Height="Auto" Margin="0,5" Name="label6" Style="{StaticResource MyLabel2}" Width="Auto" HorizontalContentAlignment="Right" />
</StackPanel>
<StackPanel DockPanel.Dock="Left" Height="Auto" Width="Auto">
<Label Content="Default is totally awesome and cool so you can just tdeal with it" Height="Auto" Margin="0,5" Name="lblJob" Style="{StaticResource MyLabel3}" Width="Auto" />
<Label Content="Default" Height="Auto" Margin="0,5" Name="lblCustomer" Style="{StaticResource MyLabel3}" Width="Auto" />
<Label Content="Default" Height="Auto" Margin="0,5" Name="lblLocation" Style="{StaticResource MyLabel3}" Width="Auto" />
<Label Content="Default" Height="Auto" Margin="0,5" Name="lblCrossing" Style="{StaticResource MyLabel3}" Width="Auto" />
<Label Content="Default" Height="Auto" Margin="0,5" Name="lblEngineer" Style="{StaticResource MyLabel3}" Width="Auto" />
<Label Content="Default" Height="Auto" Margin="0,5" Name="lblProbe" Style="{StaticResource MyLabel3}" Width="Auto" />
</StackPanel>
</DockPanel>
</Grid>
我觉得我错过了一些超级愚蠢的东西,但也许一双新鲜的眼睛会很有用。有没有办法完成我正在尝试的事情?