WPF NavigationService.Navigate 未显示在 Expression Blend 中

编程入门 行业动态 更新时间:2024-10-26 23:41:22
本文介绍了WPF NavigationService.Navigate 未显示在 Expression Blend 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试创建 WPF 应用程序,但无法在按钮单击事件上导航到自定义 xaml 文件.我正在导入导航服务方法,但由于某种原因NavigationService.Navigate"没有出现.它只向我显示 NavigationService.GetNavigationService.谁能告诉我可能是什么问题?

I am trying to create a WPF application but I cannot navigate to a custom xaml file on a button click event. I am importing the navigation service method but for some reason the "NavigationService.Navigate" is not showing up. It only shows me NavigationService.GetNavigationService. Can anyone give me an idea what the issue might be?

推荐答案

NavigationService.Navigate 是 Page 对象的一部分.如果您从

NavigationService.Navigate is part of Page object. If you inherit your XAML from

public partial class MainWindow : Page

代替

public partial class MainWindow : Window

如果你想从主窗口导航到一个页面,请在主窗口中创建一个框架,如下所示

If you want to navigate to a page from main window create a frame in mainwindow as below

<DockPanel>
        <Frame x:Name="_NavigationFrame" NavigationUIVisibility="Hidden" />
</DockPanel>

然后在你的主窗口构造函数中调用

and then in your mainwindow constructor call

_NavigationFrame.Navigate(new CustomXml());

_NavigationFrame.Navigate(new CustomXml());

对不起,CustomXaml 只是 CustomPage 的名称.

Sorry for the confusion CustomXaml is just the name of CustomPage.

我将使用以下页面导航应用程序设计

I will use the following design for page navigation application

步骤 1:创建 MainWindow.Xaml 并添加以下代码

Steps 1: Create MainWindow.Xaml and add the following Code

 <DockPanel>
            <Frame x:Name="_NavigationFrame" NavigationUIVisibility="Hidden" />
 </DockPanel>

Frame 是所有页面的占位符.

Frame is a placeholder for all the pages.

第 2 步:创建主页 MainPage.xaml(如主页)并将您打算放置在 MainWindow.XAML 中的所有代码放入此 MainPage.XAML.要在应用程序加载时打开此主页,请在 MainWindow.Xaml 构造函数中添加以下代码

Step 2: Create a main page MainPage.xaml (like home page) and place all the code you intend to place in MainWindow.XAML into this MainPage.XAML. To open this main page on application load add the following code in MainWindow.Xaml constructor

_NavigationFrame.Navigate(new MainPage());其中 MainPage() 是 MainPage.XAML 的构造函数

_NavigationFrame.Navigate(new MainPage()); where MainPage() is the constructor of MainPage.XAML

第 3 步:创建自定义页面 CustomPage.XAML(您要导航到的页面).为了从第一页导航到这个页面

Step 3: Create a custom Page CustomPage.XAML (the page you want to navigate to). In order to navigate to this page from first page

this.NavigationService.Navigate(new Uri("CustomPage.xaml", UriKind.Relative));

这篇关于WPF NavigationService.Navigate 未显示在 Expression Blend 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 02:55:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1183582.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NavigationService   WPF   Navigate   Blend   Expression

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!