this.close()不被识别为方法

时间:2016-11-24 13:47:02

标签: c# wpf xaml mahapps.metro

我试图在打开一个新窗口时关闭一个窗口,但是系统无法识别this.close()

private void Insert_Data_Click(object sender, RoutedEventArgs e)
{
            MainWindow DataWindow = new MainWindow();
            DataWindow.Show();
            this.Close();
        }

这是类声明

public partial class Home_autismo : MetroWindow

和包含的库

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;

知道为什么this.Close()无法识别?

1 个答案:

答案 0 :(得分:0)

尝试添加一个结束事件,当它关闭时会打开你的数据窗口 在窗口中添加关闭事件的XAML

 <Window x:Class="ParamCreator.PasswordWindow"    
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml
 Closed="Home_autismo_Closing">

然后在你的主类中,做这个.Close();应该认识到它

public partial class Home_autismo : MetroWindow
  {

 private void Home_autismo_Closing(object sender, EventArgs e)
    {
        MainWindow DataWindow = new MainWindow();
        DataWindow.Show();
    }
    // Logic
    If(...)
  {
  this.Close();
   }
  }