I have a context menu in my app and when I handle the MenuItem clicked, I want to navigate to another page. 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.
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:
<local:MyListBox x:Name="messageListBox"
ItemsSource="{Binding ChannelMessages}"
MaxHeight="480"
>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu ItemsSource="{Binding URLs}">
<t开发者_如何转开发oolkit: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
Does setting e.Handled = true
within your click event handler help?
精彩评论