2011-01-07 53 views
13

我在WP7應用程序中使用全景控件。其中一個PanoramaItems會將您帶到另一個頁面,然後您可以通過EmailComposeTask發送電子郵件。如果您沒有選擇發送電子郵件並按下後退按鈕,則Panorama會返回到上次選擇的項目。但是,如果您選擇發送電子郵件(因此離開應用程序),則不會返回到之前選擇的PanoramaItem。相反,它會返回到Panorama中的第一個項目。我試圖跟蹤選定的索引並設置它,但我得到一個錯誤,說SelectedIndex不可設置。這已在MSDN文檔中得到證實http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.panorama.selectedindex%28VS.92%29.aspx如何以編程方式在WP7中設置選定的全景項目

有什麼方法可以在全景圖上手動設置所選索引/項目嗎?如果不是,即使用戶離開應用程序撰寫電子郵件,是否有辦法記住所選內容?

+0

已更新,有關我最後一條有關DefaultItem的評論的澄清。 – 2011-01-08 02:07:05

+0

我在這裏回答了這個:http://stackoverflow.com/questions/17980606/how-to-smoothly-navigate-to-a-different-panorama-item/27018310#27018310 – Rivenfall 2014-11-19 13:41:32

回答

34

我不確定是否可以通過編程強制將動畫強制爲另一個PanoramaItem,但可以更改Panorama.DefaultItem

所以,你可能有3 PanoramaItem的並在OnNavigatedTo()處理程序,通過更改默認的項目:

panoramaControl.DefaultItem = panoramaControl.Items[indexToSet]; 

這應該有助於當你從一個墓碑恢復。

+1

其可前往[正確的,但我們怎麼能添加動畫效果,同時爲我導航 – 1Mayur 2012-09-08 17:38:07

+0

,這改變了全景標題的開始位置。也許這是因爲我已經應用了自定義標題模板。 – Rivenfall 2014-11-19 13:42:53

7

您可以嘗試Silicon Shark在本主題中發佈的解決方案。它被注意到工作,但只在最初的顯示 - 這不應該是一個問題,因爲你需要在墓碑後恢復狀態。

How to programmatically set the visible item in a Panorama control?

您可以從全景的SelectedIndex屬性獲得當前活動的頁面。

不幸的是,設置DefualtItem只是解決您可能已經發現的這個問題的近似值。

編輯:請注意,設置DefaultItem會更改全景圖的哪個頁面是第一頁。這是一個微妙的區別,但是您會看到重要的是如何定位標題和背景圖像。

2

設置新的選擇由

pan.SetValue(Panorama.SelectedItemProperty, pan.Items[newSelectedItem]); 

項目然而,這僅在初始所以我的想法是讓全景控制重新初始化當我們改變所選擇的項目工作。這是我的代碼,只需在Panorama.SelectedItem更改後添加此代碼即可。

(pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Collapsed; 
pan.SetValue(Panorama.SelectedItemProperty, pan.Items[(curIndex + 1) % pan.Items.Count]); 
pan.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); 
(pan.Items[curIndex] as PanoramaItem).Visibility = Visibility.Visible; 

但現在沒有過渡效果!雖然,你可以創建你自己。

它的工作非常適合我,這個頁面還創建滑動右http://xme.im/slide-or-change-panorama-selected-item-programatically

3

我測試了這裏列出沒有成功解決方案的效果。這就是我所做的,就像一個魅力!

PanoramaItem panItem = (PanoramaItem)panorama.Items[1]; 

panorama.Items.Remove(panItem); 

panorama.Items.Insert(0, panItem); 

您需要從列表中刪除面板並將其重新插入到所需的位置!

5

這是一個解決方案。它按預期工作,不會重新排列全景圖,因此您的用戶界面是一致的。

pan.SetValue(Panorama.SelectedItemProperty, panoramaItem); 
Panorama temp = pan; 
LayoutRoot.Children.Remove(pan); 
LayoutRoot.Children.Add(temp); 
LayoutRoot.UpdateLayout(); 

這不是因爲它不能很好地滑動,像全景應該一個完美的解決方案,它可能不是很有效,但另一方面使您的用戶界面保持一致沒有更改默認的項目。

1

我使用這個模型,當設備進入橫屏模式切換到一個支點,我可能會最終提取當前項目的應用程序狀態。全景圖是橫向的禁止。

private int hub_page_index; 

protected override void OnOrientationChanged(OrientationChangedEventArgs e) 
{ 
    base.OnOrientationChanged(e); 

    if (panorama.Visibility == Visibility.Visible) 
    { 
     hub_page_index = panorama.SelectedIndex; 
    } 
    else if (pivot.Visibility == Visibility.Visible) 
    { 
     hub_page_index = pivot.SelectedIndex; 
    } 

    if (e.Orientation == PageOrientation.Landscape 
    || e.Orientation == PageOrientation.LandscapeLeft 
    || e.Orientation == PageOrientation.LandscapeRight) 
    { 
    // Display Pivot in Landscape orientation 
     pivot.SetValue(Pivot.SelectedItemProperty, pivot.Items[panorama.SelectedIndex]); 
     panorama.Visibility = Visibility.Collapsed; 
     pivot.Visibility = Visibility.Visible; 
    } 
    else 
    { 
     // Display Panorama in Portrait orientation 
     panorama.SetValue(Panorama.SelectedItemProperty, panorama.Items[pivot.SelectedIndex]); 
     pivot.Visibility = Visibility.Collapsed; 
     panorama.Visibility = Visibility.Visible; 
    } 
} 
相關問題