this.close()不能被识别为法
问题描述:
我试图同时打开一个新的关闭窗口,但this.close()不被系统识别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()不承认?
答
尝试添加一个关闭事件,当它的收盘它会打开你的数据窗口 添加在您的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">
然后在你的主类,做this.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();
}
}
你试过'Application.Exit()'? – RandomStranger
你能详细说明一下吗?它在运行时不起作用,甚至不能编译?我的应用程序中有完全相同的代码,这很简单。 'Application.Exit()'在尝试切换窗口时退出不方便的应用程序。 – SilentStorm
还要确保你的xaml文件不是一个用户控件或页面,而是以''
SilentStorm