【发布时间】:2018-04-14 10:16:35
【问题描述】:
我创建了一个主窗口,它看起来像通常的登录屏幕。
一旦用户点击一个按钮,我希望整个窗口发生变化。
在我看到的所有示例中,要么我必须保留一个 stackpanel/dock,然后只有框架发生变化。
例如,我有以下主窗口 xaml:
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Frame x:Name="Main" Margin="0,35,0,0"/>
<Button Content="Button" Click="Button_Click" Margin="0,105,326,100"/>
</Grid>
</Window>
和新页面:
<Page x:Class="WpfApp1.Optimizer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="Optimizer">
<Grid Background="Black">
<Button Content="Button" HorizontalAlignment="Left" Height="91" Margin="125,87,0,0" VerticalAlignment="Top" Width="129"/>
</Grid>
</Page>
我的命令是:
private void Button_Click(object sender, RoutedEventArgs e)
{
Main.Content = new Optimizer();
}
在这种情况下,两个视图出现在同一页面上,而不是完全切换。
我正在寻找的不是这种情况。我需要改变整个窗口,而不是留下堆栈面板。
任何简单的例子都将不胜感激。
【问题讨论】: