加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

NavigationService.GetNavigationService 方法 ---NavigationSer

发布时间:2020-12-16 23:01:40 所属栏目:大数据 来源:网络整理
导读:NavigationService . GetNavigationService 方法 .NET Framework 3.5 其他版本 .NET Framework 4 .NET Framework 3.0 更新:2007 年 11 月 获取对导航器的 NavigationService 的引用,该导航器的内容中包含指定的 DependencyObject 。 命名空间: System.Win

NavigationService.GetNavigationService 方法

.NET Framework 3.5
其他版本
  • .NET Framework 4
  • .NET Framework 3.0

更新:2007 年 11 月

获取对导航器的 NavigationService 的引用,该导航器的内容中包含指定的 DependencyObject

命名空间: System.Windows.Navigation
程序集: PresentationFramework(在 PresentationFramework.dll 中)

语法

VB
C#
C++
F#
JScript
复制
public static NavigationService GetNavigationService(
	DependencyObject dependencyObject
)
J#
复制
public static NavigationService GetNavigationService(
	DependencyObject dependencyObject
)
XAML
复制
不能在 XAML 中使用方法。

参数

dependencyObject
类型: System.Windows.DependencyObject

由导航器承载的内容中的 DependencyObject

返回值

类型: System.Windows.Navigation.NavigationService

对导航器(该导航器的内容中包含指定的 DependencyObject)的 NavigationService 的引用在某些情况下可以为 null(请参见“备注”)。

异常

异常 条件
ArgumentNullException

dependencyObject 参数为 null

备注

导航器具有一个可处理内容导航的 NavigationService。WPF 具有两种导航器:NavigationWindowFrame。为了处理导航请求和管理导航生存期,导航器将使用 WPF 导航服务,该服务作为 NavigationService 类实现。由导航器承载的内容可以通过调用 GetNavigationService 方法获取对导航器的 NavigationService 的引用。

dependencyObject 符合以下条件时,GetNavigationService 将返回 null

  • NavigationWindow

  • 为符合以下条件的 Frame

    1. 由其他导航器承载。

    2. 将其 JournalOwnership 属性设置为 UsesParentJournal

  • 不是导航器承载的内容的一部分。

WPF 提供两种快捷方式来获取对 NavigationService 的引用:

  • 用于处理对 Page 的导航的 NavigationService 可以通过获取其 Page.NavigationService 属性的值从 Page 本身访问。

  • Frame 用于处理导航的 NavigationService 可以通过获取 NavigationService 属性的值进行访问。

示例

下面的示例演示 UserControl 如何通过调用 GetNavigationService 检索导航服务。

VB
C#
C++
F#
JScript
复制
void getNavigationServiceButton_Click(object sender,RoutedEventArgs e) {
    // Retrieve first navigation service up the content tree
    NavigationService svc = NavigationService.GetNavigationService(this.getNavigationServiceButton);
    if (svc != null)
    {
        // Use navigation service


...


    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读