2011-04-13 79 views
6

我看到windows手機工具箱中沒有提供下拉/組合框。我可以看到必須有一種方法來創建一個,因爲在手機的設置中,選擇一個主題本質上是一個下拉菜單。Windows Phone下拉菜單

有誰知道我可以在哪裏得到示例代碼如何創建一個?我看過幾個樣本,但是xaml看起來很長很複雜。創建這種控制真的很難嗎?

+0

Silverlight for Windows Phone確實有一個Combobox控件。 http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox(VS.95).aspx – 2011-04-13 22:03:26

回答

11

可以使用Silverlight for Windows Phone Toolkit(你真的應該使用這個)。 ListPicker控件將做你想要的。

下面是關於如何使用它的一個深入的教程:http://www.windowsphonegeek.com/articles/listpicker-for-wp7-in-depth

這裏是它的描述(從here):

ListPicker

組合框只是不冷靜在WP7 dev。因此改用ListPicker。 有兩種可用的格式。第一個 擴展到位給你的選擇。 用於短名單。第二個 帶你到另一個頁面,用 完整列表框從中選擇,然後從 返回到調用屏幕。你可以 看到這個在WP7上使用時,當你改變 設置/鈴聲&聲音。

0

選擇一個主題實際上是創建一個新的頁面,並選擇一種顏色時,它使用該值導航回到上一頁。

這是怎麼做到這一點:

private void modelListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
    //if SelectedIndex == -1, do nothing 
    if(modelListBox.SelectedIndex == -1) 
     return; 

    //navigate to the MainPage 
    NavigationService.Navigate(new Uri 
     (String.Format("/views/MainPage.xaml?MakeIndex={0}&ModelIndex={1}", m_nCameraDataIndex, modelListBox.SelectedIndex), 
     UriKind.Relative)); 

    //reset SelectedIndex 
    modelListBox.SelectedIndex = -1; 
} //end method modelListBox_SelectionChanged 

對於ddlist,我發現這一點:

http://www.simego.com/Blog/2008/05/combobox-dropdo