如何加载现有页面?

时间:2019-07-08 14:41:14

标签: c# wpf

我工作很多页面。当我返回上一页时,代码会重置该页面。我想看上一页。我怎么能这样?

public partial class MainWindow : Window
{     
    public MainWindow()
    {
        InitializeComponent();
    }


    private void BtnClickP1(object sender, RoutedEventArgs e)
    {
        Main.Content = new KK();
    }

    private void BtnClickP2(object sender, RoutedEventArgs e)
    {
        Main.Content = new AIRFOIL();
    }

    private void BtnClickP3(object sender, RoutedEventArgs e)
    {
        Main.Content = new OB();
    }
}

我在每个标签页上都使用新命令。我认为这是错误的。当我按下按钮时,我想查看现有页面。感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

如果要将修改存储在页面中,则必须使用变量。

public partial class MainWindow : Window
{
    private KK _kkPage;
    private AIRFOIL _airfoilPage;
    private OB _obPage;

    public MainWindow()
    {
        InitializeComponent();
        _kkPage = new KK();
        _airfoilPage = new AIRFOIL();
        _obPage = new OB();
    }


    private void BtnClickP1(object sender, RoutedEventArgs e)
    {
        Main.Content = _kkPage;
    }

    private void BtnClickP2(object sender, RoutedEventArgs e)
    {
        Main.Content = _airfoilPage;
    }

    private void BtnClickP3(object sender, RoutedEventArgs e)
    {
        Main.Content = _obPage;
    }
}
相关问题