WP7:从WP7上下文菜单中的MenuItem单击处理程序执行NavigationService.Navigate

时间:2011-09-05 01:29:57

标签: windows-phone-7

我的应用程序中有一个上下文菜单,当我处理单击的MenuItem时,我想导航到另一个页面。我遇到的问题是导航工作,但我没有看到其他页面加载,因为上下文菜单保持打开的点击长度。当我回击时,上下文菜单关闭,然后我看到我导航到的页面。处理这个问题的正确方法是什么?这几乎就像我需要告诉ContextMenu在我处理点击时关闭然后导航到我想要的页面。

使用我的处理程序代码更新:

private void MenuItem_Click(object sender, RoutedEventArgs e)
{
    MenuItem menuItem = sender as MenuItem;
    if (menuItem != null)
    {   
        App.appData.URL = menuItem.Header.ToString();
        NavigationService.Navigate(new Uri("/BrowserPage.xaml", UriKind.Relative));            
    }
}

XAML代码:

<local:MyListBox x:Name="messageListBox" 
                                 ItemsSource="{Binding ChannelMessages}" 
                                 MaxHeight="480"
                                 >
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <toolkit:ContextMenuService.ContextMenu>
                                    <toolkit:ContextMenu ItemsSource="{Binding URLs}">
                                        <toolkit:ContextMenu.ItemTemplate>
                                            <DataTemplate>
                                                <toolkit:MenuItem Header="{Binding}" Click="MenuItem_Click"/>
                                            </DataTemplate>
                                        </toolkit:ContextMenu.ItemTemplate>
                                    </toolkit:ContextMenu>
                                </toolkit:ContextMenuService.ContextMenu>
                                <TextBlock x:Name="MessageTextbox" Text="{Binding MessageFrom}" TextWrapping="Wrap">
                                        <TextBlock.Foreground>
                                            <SolidColorBrush Color="{StaticResource PhoneAccentColor}"/>
                                        </TextBlock.Foreground>
                                </TextBlock>
                                <TextBlock x:Name="FromTextBox" Text="{Binding MessageText}" Margin="0,0,0,19" Width="456" FontSize="21.333" TextWrapping="Wrap"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </local:MyListBox>

有什么想法吗?

由于

1 个答案:

答案 0 :(得分:0)

在点击事件处理程序中设置e.Handled = true是否有帮助?