Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a TextBlock and a ContextMenu. When I hold TextBlock I open the ContextMenu. The context menu is opening because the UI behaves properly, but I can't see the ContextMenu on screen.
This is my code:
C#
ContextMenu cm;
TextBlock tb;
private void BuildTB()
{
    cm = new ContextMenu();
    cm.Background = new SolidColorBrush(Colors.Black);
    MenuItem menuItem = new MenuItem()
    {
        Header = "Edit",
        Foreground = new SolidColorBrush(Colors.White),
        Background = new SolidColorBrush(Colors.Black)
    };
    menuItem.Click += EditItem_Click;
    cm.Items.Add(menuItem);

    tb = new TextBlock();
    tb.Text = "My text block";
    tb.Hold += OpenCM;
    ContextMenuService.SetContextMenu(tb, cm);
}

private void OpenCM(object sender, System.Windows.Input.GestureEventArgs e)
{
    TextBlock tb = (TextBlock)sender;
    ContextMenu cm = ContextMenuService.GetContextMenu(tb);
    cm.IsOpen = true;
}


What I have tried:

I searched for an answer but I can't find. If someone know the answer please help me!
Posted
Comments
[no name] 29-Sep-16 16:25pm    
You might try https://msdn.microsoft.com/en-us/library/ms743607(v=vs.110).aspx
Foothill 29-Sep-16 16:38pm    
If you're using Windows Phone 8.1, this might help
http://igrali.com/2014/04/28/show-context-menu-using-menuflyout-windows-phone-8-1/
Ionascut Mihai 29-Sep-16 16:42pm    
I am using WP 8.1, but Silverlight and I can't use MenuFlyout
Foothill 29-Sep-16 16:51pm    
Can you set the PlacementTarget? Could be that it is being displayed off-screen.
Ionascut Mihai 29-Sep-16 17:07pm    
I set it to open in the middle of the screen and it doesn't show. Can you look over my code if its good because anywhere I place it I can't see it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900