Windows Phone 7:推荐的菜单控件?

时间:2010-10-22 19:47:07

标签: silverlight windows-phone-7

在wp7中制作选项菜单的最佳方法是什么? (不是上下文菜单或应用程序栏。)目前我正在使用ListBox字符串,但我不确定这是否可行。

我也不完全确定如何让ListBox条目响应点击,以便导航到另一个页面。

2 个答案:

答案 0 :(得分:1)

对于一个简单的菜单,我已经多次使用了以下几种。

<ListBox SelectionChanged="LinkSelected">
    <ListBoxItem Name="EnterCode" >
        <TextBlock Text="Enter Code"  />
    </ListBoxItem>
    <ListBoxItem Name="Login" >
        <TextBlock Text="Login" />
    </ListBoxItem>
    <ListBoxItem Name="Register" >
        <TextBlock Text="Register" />
    </ListBoxItem>
</ListBox>

然后在事件处理程序中这样的事情:

private void WelcomeLinkSelected(object sender, SelectionChangedEventArgs e)
{
    if (sender is ListBox)
    {
        if ((sender as ListBox).SelectedIndex < 0)
        {
            return;
        }

        if ((sender as ListBox).SelectedIndex == 0)
        {
            NavigationService.Navigate(new Uri("/EnterCode.xaml", UriKind.Relative));
        }

        if ((sender as ListBox).SelectedIndex == 1)
        {
            NavigationService.Navigate(new Uri("/Login.xaml", UriKind.Relative));
        }

        if ((sender as ListBox).SelectedIndex == 2)
        {
            NavigationService.Navigate(new Uri("/Register.xaml", UriKind.Relative));
        }

        // This is very important!
        (sender as ListBox).SelectedIndex = -1;
    }
}

如果这样做,事件处理程序中的最后一行(重置SelectedIndex)非常重要,因为它允许连续多次选择相同的菜单项而不先选择另一个选项。

答案 1 :(得分:0)

您可以在列表框中为选择更改事件添加侦听器,然后使用NavigationService根据所选项目导航到任意位置。