WPF 中有Frame控件 但是如何让Frame内页的内容居中呢??
如下,将Frame控件包含在Grid(父容器)控件中:
<Grid Name="grdMain">
<Frame
Source="Index.xaml" HorizontalAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Center" HorizontalContentAlignment="Center" />
</Grid>
我们先访问grdMain的大小然后存储:
Application.Current.Properties["width"] = grdMain.ActualWidth; //记录容器的宽
Application.Current.Properties["height"] = grdMain.ActualHeight; //记录容器的高
在内页Index.xaml中加入:
public Index() {
InitializeComponent();
//给本页大小赋值
this.Height = double.Parse(Application.Current.Properties["height"].ToString());
this.Width = double.Parse(Application.Current.Properties["width"].ToString());
}
同时需要Index.xmal页面布局:
<DockPanel LastChildFill="True">
<WrapPanel VerticalAlignment="Center" HorizontalAlignment="Center"
Orientation="Horizontal" Width="700" ItemHeight="40">
<Label Width="100">用户编号:</Label>
</WrapPanel>
</DockPanel>
注意LastChildFill 启用 容器最后一个子元素填充整个DockPanel 就可以了