如何让唯一的 DockPanel 子元素停靠在顶部
下面我在菜单上说“DockPanel.Top”,但它停靠在中间。 (?)
如果我从菜单中取出高度属性,它会停靠在顶部,但高度约为 200 像素。 (?)
我认为这就是 LastChildFill 的用途。
如何让 DockPanel 的这个子元素停靠在顶部,而停靠面板中没有其他项目?
<Window x:Class="TestContainer1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="480" Width="600" Loaded="Window_Loaded">
<DockPanel HorizontalAlignment="Stretch"
Margin="0,0,0,0"
Width="Auto"
LastChildFill="True">
<Menu x:Name="panelMenuTop"
Width="Auto"
Height="25"
DockPanel.Dock="Top">
<MenuItem Header="File">
<MenuItem Header="Close"
Click="CloseApplication_Click"/>
</MenuItem>
</Menu>
</DockPanel>
</Window>
Below I say "DockPanel.Top" on Menu but it docks in the middle. (?)
If I take the Height attribute out of Menu it docks on top but is about 200px high. (?)
I thought that was what LastChildFill was for.
How can I get this child element of DockPanel to dock on the top with no other items in the dockpanel?
<Window x:Class="TestContainer1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="480" Width="600" Loaded="Window_Loaded">
<DockPanel HorizontalAlignment="Stretch"
Margin="0,0,0,0"
Width="Auto"
LastChildFill="True">
<Menu x:Name="panelMenuTop"
Width="Auto"
Height="25"
DockPanel.Dock="Top">
<MenuItem Header="File">
<MenuItem Header="Close"
Click="CloseApplication_Click"/>
</MenuItem>
</Menu>
</DockPanel>
</Window>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的菜单填满了整个区域,因此它看起来居中。 您可以给菜单一个 VerticalAlignment="Top" 或给 DockPanel 更多的子元素,正如 Henk 所说。
Your menu is filling up the entire area so it appears centered. You can just give the Menu a VerticalAlignment="Top" or give the DockPanel some more children as Henk said.