在程序退出之前调用视图代码隐藏中的方法

发布于 2024-10-06 20:21:08 字数 269 浏览 0 评论 0原文

我想在程序退出之前调用视图中的方法。我的 ViewModel 有一个 CleanUp 方法,该方法在程序退出之前被调用,可以提交 ViewModel 中的更改,但它无法调用视图中的方法。

我必须在 Richtextbox 的文档属性的视图中放置少量逻辑。在这种情况下,附加属性不能很好地工作,因为每次 Richtextbox 中的内容发生更改时,都需要创建 FlowDocument 的新表示形式,而我看不出这样的开销有什么意义。

我只是在寻找一种在应用程序即将关闭时调用视图中的方法的方法。

I'd like to call a method in a view, just prior to program exit. My ViewModel has a method CleanUp that gets called prior to program exit that can commit changes from the ViewModel, but it cannot call a method in the view.

I've had to place a small amount of logic in the view for the for the document property of a richtextbox. An attached property did not work well in this case because every time content changed in the richtextbox a new representation of a FlowDocument would need to be created and I could not see the sense in such an overhead.

I am just looking for a way to call the method in the view when the application is about to close.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

暖风昔人 2024-10-13 20:21:08

订阅 Application.Exit 事件怎么样?

How about subscribing to the Application.Exit event?

游魂 2024-10-13 20:21:08

您可以只从虚拟机引发一个事件,并将您的视图附加到该事件。

You could just raise an event from your VM and have your view attach to that event.

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