GVKun编程网logo

SilverlightNavigation(多页面导…

9

本文将分享SilverlightNavigation(多页面导…的详细内容,此外,我们还将为大家带来关于CreateaniceNavigationFlipinSilverlight3、Navigati

本文将分享SilverlightNavigation(多页面导…的详细内容,此外,我们还将为大家带来关于Create a nice Navigation Flip in Silverlight3、Navigation Framework In Silverlight、Navigation in Silverlight 3、Silverlight - NavigationService & UI Thread的相关知识,希望对你有所帮助。

本文目录一览:

SilverlightNavigation(多页面导…

SilverlightNavigation(多页面导…

主要是说一下Page控件以及使用模版.
在之前的例子中使用的是UserControl来做为页面,但通常的话我们是使用Page控件的,或者自己继承Page类来代替UserControl。因为Page提供了更方便的导航功能以及状态管理。其实,Page类是继承自UserControl的,然后添加了一些成员,一些可重写的方法和四个属性:TitleNavigationServiceNavigationContextNavigationCacheMode。其中Titel属性比较简单,不做多说,其他属性在后面都会有说到。
使用Page控件很简单,和向项目中添加UserControl一样。
1.Page
控件属性介绍
每一个Page控件内都会有一个NavigationService属性,这个属性就相当于访问Silverlight导航系统的入口,因为它提供了与Frame对象一样的方法和属性(Navigate()GoBack()GoForward(),属性有CanGoBackCanGoForwardCurrentSource等)。意思就是说在Page里面就可以进行导航了..

  1. this.NavigationService.Navigate(new Uri("/Page2.xaml",UriKind.Relative));

Page类还含有一个NavigationContext属性用来访问NavigationContext对象。使用这个属性可以获取当前的URL,使用QueryString可以获取URL中的参数( 该方法的赋值和使用在一块,与全局变量比不会太凌乱)。也就是说你可以在跳转页面的时候使用地址栏参数传值。如下:

  1. string uriText = String.Format("/Product.xaml?id={0}&type={1}",productID,productType);
  2. mainFrame.Navigate(new Uri(uriText),UriKind.Relative);

这样你就可以传两个值到目标页面了 ..
然后在Priduct.xaml页面你就可以获取到值了:

  1. int productID,type;
  2.         if (this.NavigationContext.QueryString.ContainsKey("productID"))
  3.             productID = Int32.Parse(this.NavigationContext.QueryString["productID"]);
  4.         if (this.NavigationContext.QueryString.ContainsKey("type"))
  5.             type = Int32.Parse(this.NavigationContext.QueryString["type"]);

    当让你还可以使用其他方式传值,比如在存储在Appliaction(或者在项目命名空间下创建一个类(继承App),作用是一样的,这样程序比较清晰)对象中,或者是使用独立存储都可以实现,因为使用URL参数很容易就会被篡改..

保存页面状态
通常,用户第一次进入页面或者是使用前进后退按钮切换页面,都会重新创建一个对象,当用户离开,对象就会被释放。这种情况下,如果用户输入的有信息,再回到页面就会编程默认值,页面的其他成员也会初始化成默认值。而如果可以存储页面状态的话就不会出现这种情况了。
Silverlight
允许使用Page.NavigationCacheMode属性来设置存储策略,这个属性的默认值是disabled所以不会默认不会存储页面。把属性设置为required那么页面就会保存到内存中。当用户离开页面再返回的时候就可以看到自己修改的内容依然存在,不过再次回到页面不会触发页面的构造方法,所以如果你在构造函数里写的有逻辑就需要注意了。不过会触发页面的Loaded事件。
NavigationCacheMode
的另外一个值是Enabled,如果设置成这个值,那么页面就好与Frame.CacheSize(保存页面的数量)属性关联,加入CacheSize属性设置为10,当第11个页面存储进来的话第一个页面就会被释放。而NavigationCacheMode属性设置为required属性页面就不会被计算在CacheSize中。这个可以根据自己的需要进行选择。
Page
控件的方法
    Page
类包含了几个方法使你能更加灵活的管理导航。

  • OnNavigatedTo():当页面不再是框架中的活动页面时调用。
  • OnNavigatingFrom():当页面成为框架中的活动页面时调用。

OnNavigatedFrom():在页面即将不再是框架中的活动页面时调用。

 转载别人的东西,感觉很有用,学了不少东西,也加了些自己的东西。以防遗忘。

Create a nice Navigation Flip in Silverlight3

1. Add Navigation assembly in the application and import the namespace for the assembly.

xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"

2. In this sample,you have to create 4 pages,Page1.xaml,Page2.xaml,Page3.xaml,Page4.xaml under the folder Views.

2. defiine the xaml code

 

3. write the code behind

Navigation Framework In Silverlight

Silverlight导航框架

MSDN:http://msdn.microsoft.com/zh-cn/ff432717.aspx

视频&代码:http://www.silverlight.net/learn/videos/silverlight-videos/navigation-framework/

Navigation in Silverlight 3

Key Points:

 

1. Make sure that you have already added the assembly System.Windows.Controls.Navigation in you project.

2. Import the namespace xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"

3. There are two main items here.

    navigation:Frame  this can hold the pages and controls

    navigation:Page

4. <navigation:Frame x:Name="MainFrame" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" Margin="20" UriMapper="{StaticResource uriMapper}"
                           Source="About">
         </navigation:Frame>

 

-- Source it to set the default URI for the frame.

--UriMapper is to set the UriMapper defined in the app.xaml

 

5. You can use the Navigate method of the Frame to go to where you want to. Before doing this,you should add some HyperlinkButton controls outside the Frame

 

 

6. If you want to Navigate another page when you are inside the page,you Could use

Silverlight - NavigationService & UI Thread

使用NavigationService时,发现在Navigating过程中UI Thread 被blocked住了,即使通过CompositionTarget.Rendering Event处理函数更新UI也没有效果。因为Silverlight (至少目前的4.0版本)还没有独立的Render Thread.

 

这个问题使得BusyIndicator在navigating中几乎派不上用场。。。例如

今天的关于SilverlightNavigation(多页面导…的分享已经结束,谢谢您的关注,如果想了解更多关于Create a nice Navigation Flip in Silverlight3、Navigation Framework In Silverlight、Navigation in Silverlight 3、Silverlight - NavigationService & UI Thread的相关知识,请在本站进行查询。

本文标签: