如何导航到从自定义 ApplicationPage 派生的 cs 文件(使用 xaml)
如何导航到从自定义 PhoneApplicationPage 派生的 .cs 文件?继承链如下所示:PhoneApplicationPage ->我的休闲页面包含 xaml 和 cs ->页面只需稍加修改即可导出所有内容。 NavigationService.Navigate(new Uri("/NewPage.cs", UriKind.Relative));
抛出异常...
How can I navigate to .cs file that derives from custom PhoneApplicationPage? The inheritance chain looks like this: PhoneApplicationPage -> My casual page with xaml and cs -> page that will derive all with little modifications. NavigationService.Navigate(new Uri("/NewPage.cs", UriKind.Relative));
throws exception...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,所以我有一个解决该问题的方法。正如 Barry Franklin 所说,不可能导航到 .cs 文件,但可以导航到 .xaml。解决方案是创建一个典型的 PhoneApplication 页面(xaml 和 cs),更改我们的类的基类型(我们的类需要从电话应用程序页面派生)并从构造函数中删除
InitializeComponent();
,这应该只在基类中。这样,xaml 就不会被加载,我们正在使用基类的布局。Ok, so I have a workaround for the problem. As Barry Franklin has said it is impossible to navigate to .cs file, but it is possible to .xaml. The solution is to create a typical PhoneApplication page (xaml and cs), change the base type for our class (our class needs to derive from phone application page) and remove
InitializeComponent();
from the constructor, this should be only in base class. This way the xaml is not loaded and we are using the layout from base class.您无法导航到 .cs 文件,只能导航到包含“视图”的 .xaml 文件。 .cs 文件实际上不是页面,只是驱动页面并保存实现页面功能的逻辑的“代码隐藏”。
你可以这样做:
但不是你所拥有的......
You can't navigate to a .cs file, only .xaml files which contain the "views". A .cs file is not actually a page, just the "code behind" that drives the page and holds the logic that implements the functionality of the page.
You can do this:
but not what you have...
正如 Barry 所说,仅导航到 .xaml 页面。
虽然我想知道为什么您需要从电话应用程序页面派生,但也许有更好的方法?
As Barry has said, only navigate to the .xaml page.
Though I wonder why you'd need to derive from a phoneaplicationpage, perhaps there's a better way?