在powershell中的wpf应用程序上运行代码/关闭代码
当WPF应用程序通过“ X”按钮关闭WPF应用程序时,我该如何(或)可以运行代码。如果没有,正确退出/关闭WPF应用程序的推荐方法是什么。
这是当前退出过程:
$btn_Exitwindow.Add_Click({
Disconnect-MicrosoftTeams | Out-Null
$xmlForm.Close()
})
$xmlForm.Add_Closing({$_.Cancel = $true})
$xmlForm.ShowDialog() | Out-Null
使用$ xmlform.add_closing({$_。。cancel= $ true})
杀死$ $ btn_exitwindow
按钮。如果我注释$ xmlform.add_closing({$_。cancel= $ true})
exit按钮可以工作。如何停止窗口上x
按钮的使用,并允许出口按钮正确关闭/退出应用程序?
更新: 此过程可确保MS团队在“ X”或“退出”按钮上进行盘点。
$btn_Exitwindow.Add_Click({
Disconnect-MicrosoftTeams | Out-Null
$xmlForm.Close()
})
$xmlForm.Add_Closed({ Disconnect-MicrosoftTeams | Out-Null })
$xmlForm.ShowDialog()|Out-Null
How can I (or can I) run code when a WPF application is closed via the 'X' button. If not, what is the recommended method to properly exit/close WPF applications.
This the current exit procedure:
$btn_Exitwindow.Add_Click({
Disconnect-MicrosoftTeams | Out-Null
$xmlForm.Close()
})
$xmlForm.Add_Closing({$_.Cancel = $true})
$xmlForm.ShowDialog() | Out-Null
Using $xmlForm.Add_Closing({$_.Cancel = $true})
kills the $btn_Exitwindow
button. If I comment out $xmlForm.Add_Closing({$_.Cancel = $true})
the exit button works. How would I stop the use of the X
button on the window and allow the exit button to properly close/exit the application?
Update:
This procedure ensures MS teams is disco'ed on either 'X' or 'Exit' button.
$btn_Exitwindow.Add_Click({
Disconnect-MicrosoftTeams | Out-Null
$xmlForm.Close()
})
$xmlForm.Add_Closed({ Disconnect-MicrosoftTeams | Out-Null })
$xmlForm.ShowDialog()|Out-Null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
jes,
这是一个更新,它可能会使事情变得更加清晰。
在您的表单代码中放置此块:
在您的退出按钮代码中,类似的内容:
如果您有一个取消类型按钮,则还需要添加$ noformexit = $ false,
我希望可以清除它。
Jes,
Here's an update which may make things clearer.
In your Form Code place this block:
In your Exit button code something like this:
If you have a Cancel type button you'll also need to add the $NoFormExit = $False
I hope that clears it up.