“DataContextChanging”事件?

发布于 2025-01-03 07:01:14 字数 75 浏览 2 评论 0原文

我对 WPF 很陌生,所以如果问题没有意义,请原谅我。数据上下文更改之前是否会触发一个事件?我想在数据上下文切换之前提交挂起的数据更改。

I am very new to WPF so forgive me if the question doesn't make sense. Is there an event that is fired before data context change? I want to commit the pending data changes before the data context is switched away.

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

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

发布评论

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

评论(2

无悔心 2025-01-10 07:01:14

没有 DataContextChanging 事件,但 DataContextChanged 事件提供 DataContext 的旧值:

private void Window_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
    object oldDataContext = e.OldValue;
    ...
}

There is no DataContextChanging event, but the DataContextChanged event provides the old value of the DataContext:

private void Window_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
    object oldDataContext = e.OldValue;
    ...
}
不羁少年 2025-01-10 07:01:14

没有这样的事件,如果您想确保保存数据或者用户可以选择中止编辑,您应该查看 导航 架构,其中屏幕以托管方式更改。

There is no such event, if you want to make sure data is saved or that the user can choose to abort edits you should look into navigational architectures where screens are changed in a managed way.

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