Frame.Navigate到页面的派生类的不同组件 [英] Frame.Navigate to a Page-derived class in a different assembly

查看:222
本文介绍了Frame.Navigate到页面的派生类的不同组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保持我的Windows Phone 8的基础应用空白模板视图在不同的装配不是包含应用程序清单和App.xaml中装配。

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.

我不断收到一个神秘的例外,这不利于在所有搞清楚如何解决它:

I keep receiving a cryptic exception which doesn't help at all in figuring out how to fix it:


  1. 创建从模板视觉新项目C#>商店应用程序>的Windows Phone应用程序>空白应用程序(Windows手机)。

  2. 构建和部署,工程巨大。 MainPage.xaml中的状态生成操作页面,这是正确的属性。

  3. 创建基于类库(Windows phone)系统模板从解决方案中同一类别的新项目包含原始项目,把它的 MyApp.Views

  4. 将在MainView.xaml文件使用剪切和粘贴命令新创建的项目。

  5. 加入的 MyApp.Views 的一个参照原始项目。

  6. 构建,部署,请参阅应用程序启动和故障定位鉴于只有这个异常传播回开发商的框:收到COMException 错误HRESULT E_FAIL已从COM组件的调用返回的这并未T说,在所有有用的东西绝对顶部栈帧是 Windows.UI.Xaml.Controls.Frame.Navigate(类型sourcePageType,对象参数)之后的第一个,这是 TheOriginalProject.App.OnLaunched(LaunchActivatedEventArgs E)

  1. Create a new project from the template Visual C# > Store Apps > Windows Phone Apps > Blank App (Windows Phone).
  2. Build and deploy, works great. The properties of the MainPage.xaml state the Build Action is Page, which is correct.
  3. Create a new project based on the Class Library (Windows Phone) template from the same category within the solution containing the original project, call it MyApp.Views.
  4. Move the MainView.xaml file to the newly created project using Cut and Paste commands.
  5. Add a reference to MyApp.Views to the original project.
  6. Build, deploy, see the app start and fail to locate the view only to propagate this exception back to the developer's box: ComException: Error HRESULT E_FAIL has been returned from a call to a COM component. 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).

解决方案不使用的NavigationService 与包URI,因为它似乎没有在Windows Phone 8的,或者最起码包含它的组件未在空白应用程序模板默认引用。在任何情况下,我会喜欢大大超过强烈的Pack URI输入视图名称。

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. In any event, I'd vastly prefer strongly typed view names over pack URIs.

我想一定是有人遇到这个问题已经,有什么收获?有没有一个API或工具,会给我什么从COM传来的最新E_FAIL是洞察

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?

编辑:当使用窗口。 Current.Content =新的MainPage() OnLaunched 的唯一内容,在XAML分析器异常弹出。这是无法填充异常消息,但绝对给出了一个更好的提示是怎么回事。还是无解,不过,问题只是转移到 this.InitializeComponent()的MainPage 构造函数。

When using Window.Current.Content = new MainPage() as the only content of OnLaunched, the XAML parser exception pops up. 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.

我现在看到的是 Windows.UI.Xaml.Markup.XamlParseException 解析器内部错误的WinRT的信息:对象作家'%0'的和无法更多信息加载。 X:类属性出现在128上暗示由异常对话框窗口的位置和的此线程似乎有关,但我不知道如何。

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. 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.

请注意,我也将在人们发现价值在确认没有接受我做的错误。如果您尝试重现步骤并未能重现该问题,请写一个评论,所以我可以牵制它是什么导致我与挣扎的错误。

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.

这篇关于Frame.Navigate到页面的派生类的不同组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆