页面导航
在我们讲解如何使用Live Tile之前我们先仔细讲解讲解页面导航。
Windows Phone 应用程序基于 Silverlight 页面模型,用户可在其中向前导航以浏览不同屏幕的内容。此外,您也可以使用 Windows Phone 的“返回”硬件按键向后移动PhoneApplicationFrame是应用程序唯一的框架,PhoneApplicationPage是内容不同的页面,不同的页面之间需要进行导航。
导航一般有以下方式
一种是通过Xaml直接导航。
比如写下如下程序
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<HyperlinkButton Content="SanFrancisco" Height="66" HorizontalAlignment="Left" Margin="6,6,0,0" Name="SanFrancisco" NavigateUri = "/PageSanfrancisco.xaml"
VerticalAlignment="Top" Width="200" />
</Grid>
第二种是通过NavigationService, 在xaml文件里添加Button
<Button Content="NewYork" Height="66" HorizontalAlignment="Left" Margin="12,62,0,0" Name="NewYork" VerticalAlignment="Top" Width="160" Click="NewYork_Click"/>
private void NewYork_Click(object sender, RoutedEventArgs e)
{
this.NavigationService.Navigate(new Uri("/PageNewYork.xaml", UriKind.Relative));
}
NavigationService 有以下重要的Methods
GoBack | Navigates to the most recent entry in the back navigation history, or throws an exception if no entry exists in back navigation. |
Navigate | Navigates to the content specified by the uniform resource identifier (URI). |
StopLoading | Stops asynchronous navigations that have not yet been processed. |
其中 GoForward在windows phone上面不受支持,CanGoForward在windows phone上一直都是FALSE, 调用此方法会收到InvalidOperationException. GoBack会回到历史上最新的条目,如果历史为空,可会收到异常。当页面之间切换的时候,OS不会把页面卸载或者销毁,所以当我们使用GoBack的方法时,只不过把页面重新显示,而当我们使用Navigate方法的时候,silverlight会在后台创建一个新的页面。
和五个重要的Event
FragmentNavigation | Occurs when navigation to a content fragment begins. |
Navigated | Occurs when the content that is being navigated to has been found and is available. |
Navigating | Occurs when a new navigation is requested. |
NavigationFailed | Occurs when an error is encountered while navigating to the requested content. |
NavigationStopped | Occurs when the StopLoading method is called, or when a new navigation is requested while the current navigation is in progress. |
posted on 2012-05-01 12:00 Probability 阅读(612) 评论(0) 收藏 举报