嵌入式窗体
简单布局:
<Grid Margin="6,0,-6.4,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Button Name="btnFirst" Margin="20,30,20,30">页面一</Button>
<TextBox Name="text1" Grid.Row="1" Grid.Column="0" Margin="20"> </TextBox>
<Button Name="btnSecond" Grid.Column="0" Grid.Row="2" Margin="20">页面2</Button>
<Button Name="btnThird" Grid.Column="0" Grid.Row="3">提取嵌入窗口的数据</Button>
<!--非常重点的内容,关系内容嵌套-->
<Frame Name="frame" Grid.Column="1" Grid.RowSpan="4" NavigationUIVisibility="Hidden"></Frame>
<Frame Name="frame2" Grid.Column="1" Grid.RowSpan="4" NavigationUIVisibility="Hidden"></Frame>
</Grid>
嵌入重点:
Frame
嵌入页面内容
<Grid>
<TabControl>
<TabItem Header="项目一">
<TabItem.Content>
<Grid>
<TextBox x:Name="txt1"></TextBox>
</Grid>
</TabItem.Content>
</TabItem>
<TabItem Header="项目二">
<TabItem.Content>
<Grid>
<Button Name="btn5" FontSize="30">按钮</Button>
</Grid>
</TabItem.Content>
</TabItem>
</TabControl>
</Grid>
按键生成部分
private void btnFirst_Click(object sender, RoutedEventArgs e)
{
this.frame.Content = new Page1();
}
子窗体获取主窗体值
如何在子窗体中获取主窗体的值,使用了下面方法
private void btn5_Click(object sender, RoutedEventArgs e)
{
//获取主窗口内容
MainWindow mainWindow = Application.Current.MainWindow as MainWindow;
string fatherInformation = mainWindow.text1.Text;
MessageBox.Show("显式内容是:" + fatherInformation);
}
切换页面数据保留还是消失
依旧采用单例模式进行创建