gpt4 book ai didi

c# - 在关闭时使WPF应用程序保持事件状态

转载 作者:行者123 更新时间:2023-12-03 10:22:59 25 4
gpt4 key购买 nike

已经对此有疑问,但这有点不同,所以我要问。
这是我在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 状态?谢谢。

最佳答案

来自Closingdocumentation

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com