![](/img/trans.png)
[英]How to navigate to another Page from button's Clicked event and pass listview's ItemSelected as argument?
[英]Is it possible to navigate to pivot control page by a button clicked event
我正在嘗試創建wp7樞軸控制應用程序。 單擊第一頁中的按鈕時,我想導航到另一個已經是透視頁的頁面。 可能嗎 ?
例如,如果您對數據透視控件具有以下定義:
<controls:Pivot x:Name="SettingsPivot" Title="settings">
<controls:PivotItem x:Name="GeneralSettings" Header="general settings">
<!-- Pivot Item content -->
</controls:PivotItem>
<controls:PivotItem x:Name="ConnectivitySettings" Header="connectivity settings">
<!-- Pivot Item content -->
</controls:PivotItem>
<controls:PivotItem x:Name="OtherSettings" Header="other settings">
<!-- Pivot Item content -->
</controls:PivotItem>
</controls:Pivot>
然后,您可以在按鈕單擊事件處理程序中使用以下代碼轉到其他設置:
SettingsPivot.SelectedItem = OtherSettings;
像這樣做
NavigationService.Navigate(new Uri("/Pages/Page.xaml?PivotMain.SelectedIndex = 0", UriKind.Relative));
SelectedIndex可以是任意值,具體取決於您擁有多少個樞軸項目
您可以通過以下方法導航到另一個頁面,無論它是否是樞軸頁面都無關緊要:
NavigationService.Navigate(new Uri("/SettingsPivot.xaml", UriKind.Relative));
如果您嘗試導航到另一個樞紐項目,則需要執行以下操作
int i=1; //This is the index of the pivotitem you would like to navigate to
PivotMenuName.SelectedIndex = i;
聽起來好像您需要第二段代碼。 如果您的數據透視表有2個項目(例如item1,ite2),則要從item1導航到item2,可以使用:
MyPivot.SelectedIndex = IndexOfPageToGoTo;
查看這個簡單的示例進行演示。
http://dl.dropbox.com/u/129101/WindowsPhonePivotApplication1.zip
也就是說,如果您將其用於“向導”樣式的應用程序,則不建議這樣做。 參見http://timheuer.com/blog/archive/2010/08/13/windows-phone-panorama-versus-pivot-ux-guidelines.aspx
NavigationService.Navigate(new Uri("MainPage.xaml?PivotMain.SelectedIndex = 0", UriKind.Relative));
索引為0-1-2-3 ...寫您要導航的那一個。
如果您已動態創建數據透視項目,則可以使用以下簡單代碼:
// This find object named as customName
object pvtItm = pivotName.FindName("customName");
// If this object has type of PivotItem, navigate to it
if (pvtItm is PivotItem)
{
pivotName.SelectedItem = pvtItm;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.