[英]Frame.Navigate to a Page-derived class in a different assembly
I'd like to keep my Windows Phone 8 Blank App template based view in a different assembly than the assembly containing the application manifest and App.xaml. 我想将基于Windows Phone 8 Blank App模板的视图保存在与包含应用程序清单和App.xaml的程序集不同的程序集中。
I keep receiving a cryptic exception which doesn't help at all in figuring out how to fix it: 我一直收到一个神秘的例外,在找出解决方法时根本没有帮助:
ComException
: Error HRESULT E_FAIL has been returned from a call to a COM component. ComException
: 错误HRESULT E_FAIL已从调用COM组件返回。 This doesn't say absolutely anything at all useful and the top stack frame is Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter)
following the first one, which is TheOriginalProject.App.OnLaunched(LaunchActivatedEventArgs e)
. Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter)
后面的第一个,即TheOriginalProject.App.OnLaunched(LaunchActivatedEventArgs e)
。 The solution is not to use NavigationService
with pack URI since it seems to be absent in Windows Phone 8, or at very least the assembly containing it is not referenced by default in the Blank App template. 解决方案不是将
NavigationService
与包URI一起使用,因为它似乎在Windows Phone 8中不存在,或者至少默认情况下在Blank App模板中没有引用包含它的程序集。 In any event, I'd vastly prefer strongly typed view names over pack URIs. 无论如何,我非常喜欢强类型视图名称而不是包URI。
I imagine someone must've run into this issue already, what's the catch? 我想有人必须已经遇到这个问题,有什么问题? Is there an API or a tool that will give me an insight on what the latest E_FAIL coming from COM is?
是否有API或工具可以让我深入了解来自COM的最新E_FAIL是什么?
Edit: When using Window.Current.Content = new MainPage()
as the only content of OnLaunched
, the XAML parser exception pops up. 编辑:当使用
Window.Current.Content = new MainPage()
作为OnLaunched
的唯一内容时,会弹出XAML解析器异常。 It is unable to populate an exception message, but definitely gives a better hint to what's going on. 它无法填充异常消息,但绝对可以更好地提示正在发生的事情。 Still no solution, though, the problem only moved to the
this.InitializeComponent()
in the MainPage
constructor. 但是,仍然没有解决方案,问题只转移到
MainPage
构造函数中的this.InitializeComponent()
。
What I see now is Windows.UI.Xaml.Markup.XamlParseException
with WinRT information of Parser internal error: Object writer '%0' and Additional information unable to load. 我现在看到的是
Windows.UI.Xaml.Markup.XamlParseException
,包含Parser内部错误的 WinRT信息:对象编写器'%0'和无法加载的附加信息。 x:Class
attribute is present at the position 128 hinted on by the exception dialog window and this thread seems relevant, but I can't work out how. x:Class
属性出现在异常对话框窗口提示的位置128, 这个线程似乎相关,但我无法弄清楚如何。
Please note that I'll also find values in people confirming not receiving the error I do. 请注意,我也会在确认没有收到错误的人身上找到值。 If you've tried the steps to reproduce and failed to reproduce the problem, please write a comment so I can pin down what it is that causes the error I'm struggling with.
如果你已经尝试了重现并且无法重现问题的步骤,请写一个评论,这样我就可以确定导致我正在努力解决的错误。
Alternative solution to externalizing views to a separate project while avoiding this problem is to use a Shared project project type, put the views there and reference it from the main project. 将视图外部化到单独项目同时避免此问题的替代解决方案是使用共享项目项目类型,将视图放在那里并从主项目引用它。
This does not produce a separate assembly for the views, instead the files are just grouped within their custom project, but behave as if they were part of the main project during compilation. 这不会为视图生成单独的程序集,而是将文件分组到其自定义项目中,但在编译期间表现得好像它们是主项目的一部分。 The error goes away because from the compiler point of this, there's no difference between a file in a shared project and a file directly in the main project.
错误消失了,因为从编译器的角度来看,共享项目中的文件与主项目中的文件之间没有区别。 During runtime, the type of the view doesn't need to be resolved from a different assembly, it's right there in the same assembly.
在运行时,视图的类型不需要从不同的程序集中解析,它就在同一个程序集中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.