Silverlight之页面跳转及参数传递(9)

Silverlight之页面跳转及参数传递(9),第1张

概述页面跳转及参数传递 代码下载 一、            页面跳转 1.        方式1 RootVisual this.RootVisual = new MainPage(); 2.        方式2 Content属性   Page1 p1 =new Page1();   this.Content=p1; 3.        方式3 Frame,HyperlinkButton 1)定

页面跳转及参数传递

代码下载

一、            页面跳转

1.        方式1 RootVisual

this.RootVisual = new MainPage();

2.        方式2 Content属性

  Page1 p1 =new Page1();

  this.Content=p1;

3.        方式3 FrameHyperlinkbutton

1)定义Hyperlinkbutton

          <Hyperlinkbutton Content="导航" Height="23" HorizontalAlignment="left" margin="28,12,0" name="hyperlinkbutton1" VerticalAlignment="top" WIDth="100" NavigateUri="/page1.xaml" Targetname="frame1" />

 2)定义框架

        <sdk:Frame Height="190" HorizontalAlignment="left" margin="12,75,0" name="frame1" VerticalAlignment="top" WIDth="350" Source="/page2.xaml"/>

 

后台:

this.frame1.Navigate(newUri("/SilverlightControl2.xaml",UriKind.relative));

 

4.        方式4 border

 <border borderBrush="Silver" borderThickness="1" Height="100" name="border1" WIDth="200"></border>

 

  Page2 p2=new Page2();

  border1.Child = p2;

 

5.        方式5 uriMapper

1)定义uriMapper

  <navigation:Frame x:name="ContentFrame" Style="{StaticResource ContentFrameStyle}"

                              Source="/Home" Navigated="ContentFrame_Navigated" NavigationFailed="ContentFrame_NavigationFailed">

                <navigation:Frame.UriMapper>

                  <uriMapper:UriMapper>

                    <uriMapper:UriMapPing Uri="" MappedUri="/VIEws/Home.xaml"/>

                    <uriMapper:UriMapPing Uri="/{pagename}" MappedUri="/VIEws/{pagename}.xaml"/>

                  </uriMapper:UriMapper>

                </navigation:Frame.UriMapper>

            </navigation:Frame>

2)应用

  <border x:name="linksborder" Style="{StaticResource linksborderStyle}">

                <StackPanel x:name="linksstackPanel" Style="{StaticResource linksstackPanelStyle}">

 

                    <Hyperlinkbutton x:name="link1" Style="{StaticResource linkStyle}"

                                     NavigateUri="/Home" Targetname="ContentFrame"Content="主页"/>

                                     

                    <Rectangle x:name="divIDer1" Style="{StaticResource divIDerStyle}"/>

                   

                    <Hyperlinkbutton x:name="link2" Style="{StaticResource linkStyle}"

                                     NavigateUri="/About"Targetname="ContentFrame" Content="关于"/>

                    <Rectangle x:name="divIDer2" Style="{StaticResource divIDerStyle}"/>

                    <Hyperlinkbutton x:name="link3" Style="{StaticResource linkStyle}"

                                     NavigateUri="/PageTest"Targetname="ContentFrame" Content="测试"/>

                </StackPanel>

            </border>

二、            页面间参数传递

Ø  普通参数传递方式

1)传递参数

    string uriText = String.Format("/page3.xaml?UserID={0}&Role={1}","刘备","董事长");

    this.frame1.Navigate(new Uri(uriText,UriKind.relative));

 

2)接收参数

    this.lblUserID.Text=  this.NavigationContext.queryString["UserID"].ToString();

    this.lblRole.Text= this.NavigationContext.queryString["Role"].ToString();

 

Ø  利用UriMapper

  <uriMapper:UriMapper x:name="PageMapper">

 

            <uriMapper:UriMapPing Uri="" MappedUri="/VIEws/Home.xaml"/>

            <uriMapper:UriMapPing Uri="/About/{name}/{url}" MappedUri="/VIEws/About.xaml?name={name}&amp;url={url}"/>

            <uriMapper:UriMapPing Uri="/About/{parameter}" MappedUri="/VIEws/About.xaml?parameter={parameter}"/>

 

            <uriMapper:UriMapPing Uri="/PageTest/{name}/{url}" MappedUri="/VIEws/PageTest.xaml?Username={name}&amp;url={url}"/>

            <uriMapper:UriMapPing Uri="/PageTest/{parameter}" MappedUri="/VIEws/PageTest.xaml?parameter={parameter}"/>

 

            <uriMapper:UriMapPing Uri="/{pagename}" MappedUri="/VIEws/{pagename}.xaml"/>

        </uriMapper:UriMapper>

1)传递参数:

<Hyperlinkbutton x:name="link3" Style="{StaticResource linkStyle}"

                                     NavigateUri="/PageTest/传智播客/it.cast.net" Targetname="ContentFrame" Content="测试"/>

 

2)接收参数:

  txtUserID.Text = "名字:" + this.NavigationContext.queryString["Username"] + "网址:" + this.NavigationContext.queryString["url"];

代码下载

总结

以上是内存溢出为你收集整理的Silverlight之页面跳转及参数传递(9)全部内容,希望文章能够帮你解决Silverlight之页面跳转及参数传递(9)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1068709.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存