zoukankan      html  css  js  c++  java
  • WPF学习之页间导航与页间数据传递

    WPF学习之页间导航与页间数据传递
     
     

     

    WPF学习之页间导航与页间数据传递 

    在WPF中可以非常简单的实现窗口页间的导航:这里有三种方法:

    1、Page调用NavigationService.Navigate

    新建项目,并新建一个NavigationWindow的窗体作为主窗体,并将Source指向page1.xaml

    然后新建一个页面page1,(做为主窗体的主题内容。) 在page1上方一个button1

    然后新建另一个页面page2,在page2上放一个button2,

    在button1 的click事件中就可以写实现转向的方法:

    Page2 p=new Page2();

    this.NavigationService.Navigate(page2);

    以上两行代码等价于

    this.NavigationService.Navigate(new uil("page2.xaml",UriKind.Relative));

    2、xaml中使用Hyperlink标签:

    <Hyperlink NavigateUri="page2.xaml">

    3、NavigationWindow的导航日志

    返回上一页:this.NavigationService.GoBack

     向前下一页:this.NavigationService.GoForward

     

     已上是页面之间导航,同时在转向的同时最常见的就是要数据传递:

     一.通过NavigationService.Navigate传递参数

      1.首先new一个page对象:

              Page2 page2 = new Page2();

      2.通过NavigationService.Navigate传递参数

              this.NavigationService.Navigate(page2,"frompage1");

      3.在Page2,处理NavigationWindow的LoadCompleted事件

              this.NavigationService.LoadCompleted += new LoadCompletedEventHandler(page2_LoadCompleted);

      4.在page2_LoadCompleted方法里获取传递过来的参数       

              void page2_LoadCompleted(object sender,NavigationEventArgs e)

        {

          if(e.ExtraData != null)

          {

                         string args = e.ExtraData.toString();

          }

              }

     二、通过构造函数传递参数(最易使用)

      首先new一个page对象并用NavigationService.Navigate转向

        Page2 page2 = new Page2("frompage1");

        this.NavigationService.Navigate(page2);

         在page2中定义构造函数

        public Page2(string args)

        {

          string args2 = args;

        }

     

     三、通过Application.Properties的全局数据

       用实例或URI导航到页面

              Application.Properties["Args"] = "frompage2";

         Page2 page2 = new Page2();

              this.NavigationService.Navigate(page2);

       在page2页面检查参数值

                  if(Application.Properties["Args"] != null)

         {

          string arg = Application.Properties["Args"];

         }

  • 相关阅读:
    svn diff
    Design of a ProxySharing Proxy Server
    一个很好的多代理服务器调度软件-ProxyExpert(绿色软件) 『 软件使用交流 』 赢政天下 YingZheng.com Powered by Discuz!
    关于编译Qt以及驱动的一点总结吧 Rollen Holt 博客园
    Spring Bean Scope Prototype
    spring scope="prototype" 和scope="singleton"区分
    Struts2+hibernate+spring 配置文件中scope="prototype"的作用
    nginx 多级代理
    JS中的sleep
    《2013清明忆父》!
  • 原文地址:https://www.cnblogs.com/greefsong/p/3217094.html
Copyright © 2011-2022 走看看