Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7968973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:09:43+00:00 2026-06-04T07:09:43+00:00

I have listbox in my WP7 that uses the below DataTemplete to display the

  • 0

I have listbox in my WP7 that uses the below DataTemplete to display the list items

        <DataTemplate x:Key="MetaDataTemplate">
            <Grid Width="440" Margin="4,12,0,12">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="64"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <toolkit:ContextMenuService.ContextMenu>
                    <toolkit:ContextMenu>
                        <toolkit:MenuItem Header="download" Visibility="{Binding DownloadVisible}" Command="{Binding Download}"/>
                        <toolkit:MenuItem Header="get link" Command="{Binding GetLink}"/>
                        <toolkit:MenuItem Header="delete" Command="{Binding Delete}"/>
                    </toolkit:ContextMenu>
                </toolkit:ContextMenuService.ContextMenu>                    
                <Image Height="64" Width="64" Source="{Binding Thumb}" Stretch="UniformToFill"  />
                <TextBlock Text="{Binding MetaData.Name, Mode=OneWay}" VerticalAlignment="Center" Margin="12,0,0,0" 
                           Style="{StaticResource MetaDataHeaderStyle}" Grid.Column="1" />
            </Grid>
        </DataTemplate>

defining the context menu data template makes it quite impossible to close the menu on pressing the back button! Does anyone faced this problem? How did you solve it?

I searched for the solution on internet, but couldn’t find one. Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:09:44+00:00Added an answer on June 4, 2026 at 7:09 am

    A way to do it is to have a ContextMenu variable in the code behind, and have an event handler for the Opened event of the ContextMenu in the template.

    <toolkit:ContextMenuService.ContextMenu>
                            <toolkit:ContextMenu Opened="ContextMenu_Opened">
                                <toolkit:MenuItem Header="stuff">
    
                                </toolkit:MenuItem>
                                <toolkit:MenuItem Header="more stuff">
    
                                </toolkit:MenuItem>
                            </toolkit:ContextMenu>
                        </toolkit:ContextMenuService.ContextMenu>
    

    In the Opened event handler, set the ContextMenu variable to that instance (i.e. sender).

    private void ContextMenu_Opened(object sender, RoutedEventArgs e)
        {
            menu = sender as ContextMenu;
        }
    

    Finally, override OnBackKeyPress, so that if the variable is not null, and the menu is open, then close the menu and cancel the back event.

    protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (menu != null && menu.IsOpen)
            {
                menu.IsOpen = false;
                e.Cancel = true;
            }
    
            base.OnBackKeyPress(e);
    
        }
    

    That should do it! Let me know if you have any issues, or need me to paste the full code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have listbox that displays information about list of objects: <ListBox Grid.Column=0 Height=152 Name=CustomersList
I currently have a listBox in a WP7 application that uses databinding to populate
I have a ListBox bound to a list of Items (for arguement, lets say
I have a ListBox that I've bound to a List of ordered times. When
I writing wp7 silverlight app. I have a listbox with items. I want each
I have a Listbox within my WP7 application, and inside the DataTemplate I have
So I have a detail page on my WP7 app that shows a listbox
I cannot view the vertical scroll bar for Listbox control in WP7. I have
I have a ListBox containing a group of 'Expander' items, and what I would
I have a listbox containing Users. The datasource is an generic list of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.