在powershell中的wpf应用程序上运行代码/关闭代码

发布于 2025-02-05 03:46:35 字数 959 浏览 3 评论 0原文

当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.

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我爱人 2025-02-12 03:46:35

jes,

这是一个更新,它可能会使事情变得更加清晰。

在您的表单代码中放置此块:

 #Catch clicking of Form CloseBox
  $NoFormExit = $True
  $Window.Add_Closing({param($Sender,$ExitForm)
    
          $ExitForm.Cancel= $NoFormExit
  })

在您的退出按钮代码中,类似的内容:

  $OKButton.Add_Click({
        $NoFormExit = $False
        $Window.Close()
  })

如果您有一个取消类型按钮,则还需要添加$ noformexit = $ false,

我希望可以清除它。

Jes,

Here's an update which may make things clearer.

In your Form Code place this block:

 #Catch clicking of Form CloseBox
  $NoFormExit = $True
  $Window.Add_Closing({param($Sender,$ExitForm)
    
          $ExitForm.Cancel= $NoFormExit
  })

In your Exit button code something like this:

  $OKButton.Add_Click({
        $NoFormExit = $False
        $Window.Close()
  })

If you have a Cancel type button you'll also need to add the $NoFormExit = $False

I hope that clears it up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文