我对Dock面板知之甚少,以下是使用的代码:
<DockPanel LastChildFill="True" >
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" VerticalAlignment="Center" Margin="10" >
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left" VerticalAlignment="Center" >
<TextBlock Height="24" Name="Welcome" Text="Welcome" FontSize="14" />
</StackPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right" VerticalAlignment="Center" >
<TextBlock Height="24" Name="Welcomee" Text="Welcomee" FontSize="14" />
</StackPanel>
</StackPanel>
</DockPanel>
结果如下:
WelcomeWelcomee
但是,代码必须是这样的:
Welcome Welcomee
那么请你告诉我在哪里误解了这个概念。
答案 0 :(得分:4)
您的第一个StackPanel不应包含其他两个堆栈面板。
它包含另外两个。 DockPanel.Dock="left"
仅适用于DockPanel的直接子项。
<DockPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" VerticalAlignment="Center" Margin="10" >Top
</StackPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left" VerticalAlignment="Center" >
<TextBlock Height="24" Name="Welcome" Text="Welcome" FontSize="14" />
</StackPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right" VerticalAlignment="Center" >
<TextBlock Height="24" Name="Welcomee" Text="Welcomee" FontSize="14" />
</StackPanel>
</DockPanel>