导航窗口 - 它在哪里?

发布于 2024-09-14 09:24:09 字数 686 浏览 11 评论 0原文

我的 WPF 应用程序变得非常痛苦。我已经创建了一个窗口,并且想在单击按钮时加载另一个页面。我以为这会很简单,但事实似乎并非如此。我设法使用 this.content = new UserPage() 加载其他页面。但是,从这个用户页面,我无法返回主窗口。我无法使用 this.content 因为该窗口不能是子窗口。

因此,我四处搜索,发现我应该使用 NavigationService 来使事情变得更容易。我尝试使用 NavigationService.GetNavigationService(this) 但这不起作用,因为它总是返回 null。我认为这是因为我的主窗口是从 Window 派生的,而不是 NavigationWindow 。有没有办法将我的窗口转换为导航窗口而无需再次启动项目?每当我创建一个新文件时,都没有 NavigationWindow 模板 - 只有窗口、页面、用户控件等...

我尝试用 NavigationWindow 手动替换 XAML,它运行良好,但 NavigationService 方法仍然返回 null。顶部有一个栏,还有后退和前进箭头(均已禁用),但我真的不需要这个。我只想使用 Navigate() 方法,以便我可以轻松地在页面之间切换。 关于我能做什么有什么想法吗?

感谢您的帮助,这让我发疯! :)

My WPF application is becoming a real pain. I have created a Window and would like to load another page when I click on a button. I assumed this would be straightforward, but it doesn't seem to be. I manage to load the other page by using this.content = new UserPage(). However, from this UserPage, I can't get back to my main window. I can't use this.content because the window can't be a child.

Therefore, I searched around and found out I should be using NavigationService to make things a lot easier. I tried to use NavigationService.GetNavigationService(this) but this didn't work as it always returned null. I figured it's because my main window is derived from Window and not NavigationWindow. Is there a way to convert my Window into a NavigationWindow without starting the project again? Whenever I create a new file, there's no NavigationWindow template - only Window, Page, User Control etc...

I tried manually replacing the XAML with NavigationWindow and it ran fine, but the NavigationService method still returned null. There was a bar at the top as well with back and forward arrow (both disabled), but I don't really need this. I would just like to use the Navigate() method so that I can easily switch between pages.
Any ideas on what I can do?

Thanks for any help, this is driving me nuts! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ゃ人海孤独症 2024-09-21 09:24:09

我尝试手动替换 XAML
使用 NavigationWindow 并且运行良好,
但 NavigationService 方法仍然
返回空

如果您的窗口已经是 NavigationWindow,则不需要 NavigationServiceNavigationWindow 有一个 Navigate 方法。

您还可以使用标准Window 并在其上放置Frame 控件。它的工作原理大致类似于 NavigationWindow,只不过它嵌入在窗口中

I tried manually replacing the XAML
with NavigationWindow and it ran fine,
but the NavigationService method still
returned null

You don't need the NavigationService if your window is already a NavigationWindow. NavigationWindow has a Navigate method.

You can also use a standard Window and put a Frame control on it. It works roughly like a NavigationWindow, except that it's embedded in a window

吻安 2024-09-21 09:24:09

Skoder,

我不太确定你想做什么,但我会看看是否可以提供帮助。首先,听起来您想要一个导航窗口。如果您只想在应用程序中使用一个页面,那么您的第一种方法将起作用,但是当您谈论多个页面并想要从一个页面移动到另一个页面时,您正在谈论导航窗口。

其次,一旦您选择了导航窗口,XAML 就应该很简单,只需将 Window 替换为 NavigationWindow 即可,除非您现在需要意识到您将不再直接控制窗口的内容。相反,内置的 NavigationService 将处理这个问题。哦,您不需要创建显式的 NavigationService,因为该类已经提供了一个。您只需要导航:

 this.Navigate(new Url("pack://aplication:,,,/MyAssembly,component/MyPage.xaml", UriKind.Absolute));

或者,可以使用 XAML:

Source = "pack://aplication:,,,/MyAssembly,component/MyPage.xaml"

此时,您将需要一些界面来允许用户从一个页面转到下一个页面(例如 Breadcrumb 控件或 TreeView),但是一旦他们到达那里,内置的旅行控制中将允许您浏览自动为您维护的日志。也就是说,导航的大部分基本工作已经为您完成,您只需要弄清楚用户如何向前导航到某些内容即可。

但此时,事情可能会变得非常奇怪。我自己也遇到过这个。由于您无法向框架显式添加网格或任何其他内容,因此您需要更改导航窗口的模板,以便添加构成正常应用程序的额外控件。菜单和工具栏等内容不是标准 WPF NavigationWindow 的一部分。

请原谅这种无耻的自我推销,但我开发了一个产品,因为我遇到了这些限制,而且市场上没有任何可用的产品。您可以在以下位置查看演示:

http://www.teraque.com/ products/explorer-chrome-suite/

它被设计为 Microsoft 免费提供的 WPF NavigationControl 的专业版本。看看演示,如果您不想购买该套件,如果这是您希望采用的应用程序的方向,我很乐意提供指导。

此致,

唐纳德·罗伊·艾雷

[电子邮件受保护]

Skoder,

I'm not really sure what you are trying to do, but I'll see if I can help. First, it sounds like you want a NavigationWindow. If you only want one Page in your application, then your first approach will work but the minute you talk about more than one page and wanting to move from one page to another, you are talking about a NavigationWindow.

Second, once you choose a navigation window, the XAML should be straight forward, just replace Window with NavigationWindow and you should be good to go except you need to realize now that you will no longer directly control the content of the window. Instead the built-in NavigationService will handle this. Oh, and you don't need to create an explicit NavigationService as the class already provides one. You simply need to navigate:

 this.Navigate(new Url("pack://aplication:,,,/MyAssembly,component/MyPage.xaml", UriKind.Absolute));

alternatively, use can use XAML:

Source = "pack://aplication:,,,/MyAssembly,component/MyPage.xaml"

At this point, you will need some interface to allow your users to get from one page to the next (e.g. Breadcrumb control or TreeView), but once they are there the built-in travel control will allow you to navigate through the Journal that is maintained automatically for you. That is, most of the basic work of navigating is done for you, you just need to figure out how the user navigates forward to some content.

But at this point, things can get pretty strange. I ran into this myself. Since you can't add a grid or any other content explicity to the frame, you need to alter the template of the NavigationWindow in order to add the extra controls that make up a normal application. Things such as Menus and Toolbars are not part of the standard WPF NavigationWindow.

Forgive this shameless bit of self-promotion, but I've built a product because I ran into these limitations and there wasn't anything available on the market. You can take a look at the demo at:

http://www.teraque.com/products/explorer-chrome-suite/

It was designed to be the professional version of the WPF NavigationControl that Microsoft gives away for free. Take a look at the demo, if you don't want to purchase the suite, I'd be happy to give away pointers if this is the direction you want to take your application.

Sincerely,

Donald Roy Airey

[email protected]

笑脸一如从前 2024-09-21 09:24:09

我已经这样做了,但无法弄清楚如何从位于框架中的页面中的 vb.net 语句重新加载父窗口。
我希望在 window_loaded 函数中执行一些代码。

I've done that but haven't been able to work out how to get the parent window reloaded from a vb.net statement in the page which is located in the frame.
I have some code in the window_loaded function I wish to execute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文