我正在学习WPF并且我正在尝试使用一个表单,该表单由顶部的工具栏组成,底部是状态栏,其余部分将由用于数据输入的控件占用。
这是我到目前为止所做的:
<Window x:Class="MyApp.MyForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyForm" Height="346" Width="459">
<DockPanel>
<ToolBarTray DockPanel.Dock="Top">
<ToolBar>
<Button Command="New" Content="New" />
<Button Command="Open" Content="Open" />
<Button Command="Save" Content="Save" />
</ToolBar>
</ToolBarTray>
</DockPanel>
</Window>
如何在底部添加状态栏,以及另一个将占用表单其余部分的面板?
答案 0 :(得分:10)
您可以使用DockPanel来排列控件。像这样 工具栏将停靠在顶部,状态栏位于底部,剩余空间将分配给数据网格,因为我们已在dockpanel中将“LastChildFill”设置为true。
<Window x:Class="MyApp.MyForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyForm" Height="346" Width="459">
<DockPanel LastChildFill="True">
<ToolBarTray DockPanel.Dock="Top">
<ToolBar>
<Button Command="Edit" Content="Edit" />
<Button Command="Delete" Content="Delete" />
<Button Command="Refresh" Content="Refresh" />
</ToolBar>
</ToolBarTray>
<StatusBar Name="statusbar" DockPanel.Dock="Bottom">statusbar</StatusBar>
<DataGrid Name="grdEmployees" ItemsSource="{Binding EmpCollection}" />
答案 1 :(得分:0)
建议你使用可以处理复杂布局的网格。
<Grid>
<Grid.RowDefinitions>
<RowDefinition x:Name="Toolbar1" Height="50" />
<RowDefinition x:Name="Toolbar2" Height="50" />
<RowDefinition x:Name="ForDataVisualize" Height="*" />
<RowDefinition x:Name="ForStatusbar" Height="25" />
</Grid.RowDefinitions>
</Grid>
答案 2 :(得分:0)
这就是我用你的代码玩的东西:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyForm" Height="346" Width="459">
<DockPanel Margin="0,0,0,-4">
<ToolBarTray DockPanel.Dock="Top">
<ToolBar>
<Button Command="New" Content="New" />
<Button Command="Open" Content="Open" />
<Button Command="Save" Content="Save" />
</ToolBar>
</ToolBarTray>
<StatusBar Height="21" VerticalAlignment="Bottom" DockPanel.Dock="Bottom" HorizontalAlignment="Right" Width="431" Margin="0,0,10,0"/>
<Grid Height="267" VerticalAlignment="Top" Width="451" DockPanel.Dock="Left"/>
</DockPanel>
</Window>