WPF - PRISM 视图激活后,验证下降
要在 WPF/PRISM 中切换视图,我在区域上使用激活/停用。
我有一个实现了 IDataErrorInfo 的基类,当我的模块加载我的视图时,验证会立即发生。当我切换到另一个视图并返回时,验证消失了。没有工具提示或标记表明字段包含错误。唯一停止的是我对“提交”按钮的安全检查。
我认为不太用户友好。
因此,我目前正在寻找一种在激活后重新评估视图的方法......
[根据请求提供代码]
To switch view in WPF/PRISM I use activate/deactivate on the region.
I'm having a base class with IDataErrorInfo implemented, when my module loads my view, the validation instantly happens. When I switch towards an other view and back, the validation is gone.. No tooltips or markings that the fields contain errors. The only thing that is stopping is my safeguard check on my "submit"-button.
Not very user-friendly I suppose.
So I'm currently looking towards a way to re-evaluate the view after activation...
[Code on request]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您始终可以清除视图并将它们再次添加到导航上的 RegionManager 中。通常这与自定义代码有关,并且很难查明其他错误,它可能是您从单例容器中获得的错误,或者当您重新使用 ViewModel 时您不再验证,等等 清除RegionManager
区域中的所有视图然后再次激活是通常有效的强力解决方案,好的实践解决方案是在 ViewModel 中处理该问题或编写自己的 RegionBehavior 并添加它。至棱镜在引导程序中。
您在两个 Prism 的参考实现上都有一些
RegionBehavior
类的示例。You can allways clear the Views and add them again to the RegionManager on navigation. Usually that is related to custom code, and it's hard to pinpoint others errors, it can be something you're getting from the container that is a singleton, or when you're re-using the ViewModel you're not validating anymore, etc.
The clear all views in the RegionManager region then activate again is the brute force solution that usually works, the good practice solution is somewhere between taking care of that in the ViewModel or writing your own
RegionBehavior
and adding it to Prism in the Bootstrapper.You have some examples of
RegionBehavior
classes on both of Prism's Reference Implementations.