已经对此有疑问,但这有点不同,所以我要问。
这是我在Window内的xaml:
<i:Interaction.Triggers>
<i:EventTrigger EventName="Closing">
<i:InvokeCommandAction Command="{Binding ClosingCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
这将关闭Command:
public virtual ICommand ClosingCommand
{
get { return new RelayCommand(ClosingExecute); }
}
这是执行:
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
}
}
在这种情况下如何使我的应用程序保持 Activity 状态?谢谢。
最佳答案
来自Closing
的documentation
Closing can be handled to detect when a window is being closed (for example, when Close is called). Furthermore, Closing can be used to prevent a window from closing. To prevent a window from closing, you can set the Cancel property of the CancelEventArgs argument to true.
您需要将事件处理程序连接到此事件,并将
Cancel
设置为true
。如果要以mvvmy的方式执行此操作,this answer可能会帮助您将eventargs连接到命令参数
关于c# - 在关闭时使WPF应用程序保持事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25936522/