WPF/Prism:视图返回 System.Object
我是 WPF 和 Prism 的新手,但我已经了解到您必须在 Unity 中将 View 注册为对象:
Container.RegisterType<Object,MyView>("My.Assembly.MyView");
不过,当我使用
var RelativeUriToMyView = new Uri("My.Assembly.MyView",UriKind.Relative);
RegionManager.RequestNavigate(RelativeUriToMyView, RegionName, CallbackResult);
MyView 显示为 System.Object 时,CallbackResult 不包含错误。
我缺少什么?如果需要,我很乐意提供更多信息。
I am new to WPF and Prism, but I already learned that you have to register a View in Unity as an object:
Container.RegisterType<Object,MyView>("My.Assembly.MyView");
Still, when I use
var RelativeUriToMyView = new Uri("My.Assembly.MyView",UriKind.Relative);
RegionManager.RequestNavigate(RelativeUriToMyView, RegionName, CallbackResult);
the MyView displays as System.Object, and the CallbackResult contains no Error.
What am I missing? I'm happy to provide more information if needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要查看 PRISM 源代码中的 RegionNavigationContentLoader.cs;这是为您加载视图的代码。
有几种辅助方法可以获取 URI、提取查询字符串并创建用于查找视图的“名称”并将其转换为对象。
本质上,您用来将具体类作为对象与 Unity 关联起来的名称与您尝试使用 Unity 解析该对象时需要使用的名称相同。这是一些伪代码来解释,
如果这些都没有帮助,请发布relativeUriToMyView,以便我可以看到内容。
祝你好运。
You would want to look at the RegionNavigationContentLoader.cs in the PRISM source code; Here is the code that is loading the view for you.
There are several helper methods that take the URI, extract the query string, and create the 'name' used to lookup your view and cast it as an object.
Essentially, the name you are using to associate your concrete class as an object with Unity is the same one you'll need to use when you try to resolve the object with Unity. Here is some pesudocode to explain,
If none of this helps, post the RelativeUriToMyView so I can see the contents.
Good luck.
该问题似乎是由于使用全名 (My.Assembly.MyView) 而不是名称 (MyView) 注册视图引起的。
编辑:
更改了问题以更准确地反映问题。
The issue seemed to be caused by registering the view with its FullName (My.Assembly.MyView) instead of its Name (MyView).
Edit:
Changed the question to more accurately reflect the issue.