简体   繁体   English

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

[英]WP7: Executing a NavigationService.Navigate from a MenuItem click handler from a Context menu on WP7

I have a context menu in my app and when I handle the MenuItem clicked, I want to navigate to another page. 我的应用程序中有一个上下文菜单,当我处理单击的MenuItem时,我想导航到另一个页面。 The issue I am having is that the navigation works but I don't see the other page load since the context menu remains open for the length of the click. 我遇到的问题是导航正常,但是我没有看到其他页面加载,因为上下文菜单在单击时保持打开状态。 When I hit back, the context menu closes and then I see the page I navigated to. 当我回击时,上下文菜单关闭,然后我看到导航到的页面。 What's the correct way to handle this? 处理此问题的正确方法是什么? It's almost like I need to tell the ContextMenu to close when I handle the click and then navigate to the page I want. 几乎就像我需要在处理单击然后告诉我想要的页面时告诉ContextMenu关闭。

updated with my handler code: 用我的处理程序代码更新:

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 Code: 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>

Any ideas? 有任何想法吗?

Thanks 谢谢

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM