Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 关闭时保持WPF应用程序处于活动状态_C#_Wpf_Mvvm_Mvvm Light - Fatal编程技术网

C# 关闭时保持WPF应用程序处于活动状态

C# 关闭时保持WPF应用程序处于活动状态,c#,wpf,mvvm,mvvm-light,C#,Wpf,Mvvm,Mvvm Light,关于这一点已经有问题了,但这有点不同,所以我要问。 这是我的xaml内部窗口: <i:Interaction.Triggers> <i:EventTrigger EventName="Closing"> <i:InvokeCommandAction Command="{Binding ClosingCommand}" /> </i:EventTrigger> </i:Interaction.Triggers&g

关于这一点已经有问题了,但这有点不同,所以我要问。 这是我的xaml内部窗口:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="Closing">
        <i:InvokeCommandAction Command="{Binding ClosingCommand}" />
    </i:EventTrigger>
</i:Interaction.Triggers>
这是执行:

public virtual void ClosingExecute()
{
   MessageBoxResult result = MessageBox.Show("Close the application?", "Shut Down", MessageBoxButton.YesNo);

    if(result == MessageBoxResult.Yes)
    {
        Application.Current.Shutdown();
    }
    else
    {
       //I don't know what to write
    }

}
在这种情况下,我如何保持我的应用程序有效?谢谢。

从<代码>结束

可以处理关闭以检测窗口何时关闭(例如,何时调用Close)。此外,关闭可用于防止窗口关闭。要防止窗口关闭,可以将CancelEventArgs参数的Cancel属性设置为true

您需要将事件处理程序连接到此事件,并将
Cancel
设置为
true


如果您希望以mvvmy方式执行此操作,可能会帮助您将eventargs连接到命令参数

难道您不能什么都不做吗?是什么导致应用程序关闭?代码未输入您的if语句?当我单击“否”时,应用程序将关闭。我想这是因为这是关于关闭而不是关闭的讨论
<Application
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="MainWindow.xaml"
    ShutdownMode="OnExplicitShutdown">
</Application>

ShutdownMode="OnExplicitShutdown"
<Application
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="MainWindow.xaml"
    ShutdownMode="OnExplicitShutdown">
</Application>

ShutdownMode="OnExplicitShutdown"