原文地址:http://www.cnblogs.com/xieLongBao/archive/2012/02/26/2368377.html
跟林永堅老師學WP7開發
- 內容概覽
- 使用xaml進行導航
- 使用C#代碼進行導航
- 地址別名
- 頁面之間的資料傳遞
- 回退按鈕
為了更好的控制導航,我們需要Crowdsourced Security Testing道頁面的架構與架構:
- Frame
- 只有一個單獨的PhoneApplicationFrame
- 包含一個或多個PhoneApplicationPage
- 也包含系統托盤和應用程式欄
- Page
- 包含標題,可以有獨立的應用程式欄
- Page之間可以相互導航
- SIlverlight for window phone 使用以頁面為基礎的頁面導航
- 與web的頁面導航類似
- 每個獨立的都有唯一的URI
- 每個獨立的頁面都是沒有狀態的
概念介紹完了,下面就是例子了:
在導航裡的一個很重要的控制項:hyplinkbutton,所以我先拖四個hyplinkbutton到介面中來,
這樣就是首頁面了,接下來再建立一個新的導航到的頁面Music.xaml到views目錄下,然後添加contant為音樂的hyperlinkbutton的NavigateUri
這樣啟動程式就可以正常的導航了,下面的三個按照同樣的操作就可以了,
第三步:在頁面裡使用,把HyperLinkButton的NavigationURi屬性修改成如下,到此別名導航就完成了。
?
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <HyperlinkButton Content="音樂" Height="30" HorizontalAlignment="Left" NavigateUri="Music" Margin="29,131,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="115" /> <HyperlinkButton Content="視頻" Height="30" HorizontalAlignment="Left" NavigateUri="Vedio" Margin="29,60,0,0" Name="Vedio" VerticalAlignment="Top" Width="115" /> <HyperlinkButton Content="瀏覽器" Height="30" HorizontalAlignment="Left" NavigateUri="WebBrowser" Margin="29,283,0,0" Name="WebBrowser" VerticalAlignment="Top" Width="115" /> <HyperlinkButton Content="圖片" Height="30" HorizontalAlignment="Left" NavigateUri="Picture" Margin="29,207,0,0" Name="hyperlinkButton4" VerticalAlignment="Top" Width="115" /> <Button Content="音樂" Height="72" HorizontalAlignment="Left" Margin="241,131,0,0" Name="musicbutton1" VerticalAlignment="Top" Width="160" Click="musicbutton1_Click" /> <Button Content="視頻" Height="72" HorizontalAlignment="Left" Margin="241,39,0,0" Name="videobutton2" VerticalAlignment="Top" Width="160" Click="videobutton2_Click" /> <Button Content="瀏覽器" Height="72" HorizontalAlignment="Left" Margin="241,323,0,0" Name="webbroserbutton3" VerticalAlignment="Top" Width="160" Click="webbroserbutton3_Click" /> <Button Content="圖片" Height="72" HorizontalAlignment="Left" Margin="241,225,0,0" Name="picturebutton4" VerticalAlignment="Top" Width="160" Click="picturebutton4_Click" /> </Grid> |
頁面修改為
?
<HyperlinkButton Content="歌曲1" NavigateUri="Music/歌曲1" Height="30" HorizontalAlignment="Left" Margin="175,230,0,0" Name="hyperlinkButton2" VerticalAlignment="Top" Width="200" /> |
注意:NavigationService預設不能傳遞對象(可以通過使用App類的靜態屬性、SIngleton類、把對象分解為QueryString來傳遞......)