在 Caliburn Micro 中使用 WindowManager 时如何从对话框返回对象
我刚刚开始使用 Caliburn Micro WindowManager。
我已成功显示一个包含 WPF 视图的模式对话框。
我需要从对话框返回一个对象。最好的方法是什么?
背景 - 这是一个登录对话框。我需要验证用户名和密码并返回用户配置信息。
I'm just starting out with the Caliburn Micro WindowManager.
I have managed to display a modal dialog containing my WPF view.
I need to return an object from the dialog. What is the best way to do this?
Background - this is a login dialog. I need to validate the username and password and return user configuration information.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以想到两种方法来做到这一点。我假设您的登录视图模型类派生自 Caliburn.Micro.Screen。
1) 让视图模型(代表您的登录屏幕)公开一个返回用户配置的属性。然后,您可以在成功登录后访问它,如下所示:
2) 成功登录后将用户配置信息添加到应用程序的资源字典中。下面的示例显示您在登录视图模型内的“登录”方法中进行设置。
There are two ways I can think of to do this. I'm assuming your Login viewmodel class derives from Caliburn.Micro.Screen.
1) Have the view model (representing your login screen) expose a property that returns the user configuration. You can then access it upon a successful login like below:
2) Add the user configuration information to the application's resource dictionary upon a successful login. The example below shows you setting this inside a "Login" method inside the login viewmodel.
我不知道 Caliburn Micro WindowManager 但如果您的模态对话框视图有一个视图模型,那么如何使用可以访问对象的视图模型呢?
在我的项目中,有一个 ILoginViewModel,我在 app.cs 中的 DialogResult=true 之后使用它。 (我使用 MEF 导出此信息,因此我的模块可以轻松访问)
i dont know Caliburn Micro WindowManager but if your modal dialog view has a viewmodel, what about to just take the viewmodel where you can access your object?
in my project a have a ILoginViewModel which i use after DialogResult=true in my app.cs. (i export this information with MEF, so its easy to access for my moduls)