WPF 和XAML问题
我是 WPF 和 WPF 新手沙姆尔 我不知道如何锚定如何停靠...... 在此屏幕上,灰色表示状态栏已停靠,但网格和菜单并非所有组件都在画布中。 这是 XAML
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication6.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Grid x:Name="LayoutRoot">
<Canvas>
<StackPanel Height="40" Width="624" VerticalAlignment="Top" HorizontalAlignment="Center">
<Menu Height="39" Margin="1,0,0,0">
<Menu.Background>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFF6F6F6" Offset="0.25"/>
<GradientStop Color="#FFEAE8E8" Offset="0.25"/>
<GradientStop Color="#FFDCD9D9" Offset="0.8"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Menu.Background>
</Menu>
</StackPanel>
<StackPanel Height="356" Canvas.Top="44" Width="161" HorizontalAlignment="Left">
<Expander Header="Expander" Height="107">
<Grid Background="#FFE5E5E5"/>
</Expander>
</StackPanel>
<StackPanel Height="360" Canvas.Left="161" Canvas.Top="40" Width="463">
<DataGrid Height="361"/>
</StackPanel>
</Canvas>
<StackPanel Height="40" Margin="-1,0,0,0" VerticalAlignment="Bottom">
<StatusBar Height="40" Background="#FF897676"/>
</StackPanel>
</Grid>
Im new in WPF & Xaml
I dont know how to anchor how to dock...
On this screen gray is statusBar is docked but grid and menu is not all components are in canvas.
This is XAML
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication6.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Grid x:Name="LayoutRoot">
<Canvas>
<StackPanel Height="40" Width="624" VerticalAlignment="Top" HorizontalAlignment="Center">
<Menu Height="39" Margin="1,0,0,0">
<Menu.Background>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFF6F6F6" Offset="0.25"/>
<GradientStop Color="#FFEAE8E8" Offset="0.25"/>
<GradientStop Color="#FFDCD9D9" Offset="0.8"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Menu.Background>
</Menu>
</StackPanel>
<StackPanel Height="356" Canvas.Top="44" Width="161" HorizontalAlignment="Left">
<Expander Header="Expander" Height="107">
<Grid Background="#FFE5E5E5"/>
</Expander>
</StackPanel>
<StackPanel Height="360" Canvas.Left="161" Canvas.Top="40" Width="463">
<DataGrid Height="361"/>
</StackPanel>
</Canvas>
<StackPanel Height="40" Margin="-1,0,0,0" VerticalAlignment="Bottom">
<StatusBar Height="40" Background="#FF897676"/>
</StackPanel>
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不希望这些东西出现在
Canvas
中。我不确定我是否在 WPF 中使用过Canvas
。DockPanel
是你的朋友,它是这样工作的:DockPanel
中的每个控件都有一个DockPanel.Dock
附加属性:Left、Top、右边,还是底部DockPanel
中声明的最后一个控件。因此,即使您希望“填充”控件位于最顶部,您也可以将其设置为 DockPanel 中的最后一项并设置 DockPanel.Dock="Top" 。从最基本的角度来说,
DockPanel
的使用方式与StackPanel
类似,只不过它会填充可用空间。You don't want these things to go in a
Canvas
. I'm not sure I've ever used aCanvas
in WPF.DockPanel
is your friend, and this is how it works:DockPanel
gets aDockPanel.Dock
attached property : Left, Top, Right, or BottomDockPanel
. So, even if you want the "fill" control to be at the very top, you make it the last item in theDockPanel
and setDockPanel.Dock="Top"
.At its most basic,
DockPanel
can be used just likeStackPanel
except it will fill available space.