C# 尝试显示时出现弹出菜单错误

C# 尝试显示时出现弹出菜单错误,c#,windows-phone-8.1,popupmenu,C#,Windows Phone 8.1,Popupmenu,我对弹出菜单有一个奇怪的问题(这不是我第一次在代码中使用它,所以我不明白为什么会发生这种情况) 这是显示弹出菜单的代码: PopupMenu p = new PopupMenu(); p.Commands.Add(new UICommand { Label = "Delete gear", Id = 0 }); p.Commands.Add(new UICommand { Label = "-", Id = 1 }); if (i

我对弹出菜单有一个奇怪的问题(这不是我第一次在代码中使用它,所以我不明白为什么会发生这种情况)

这是显示弹出菜单的代码:

        PopupMenu p = new PopupMenu();
        p.Commands.Add(new UICommand { Label = "Delete gear", Id = 0 });
        p.Commands.Add(new UICommand { Label = "-", Id = 1 });

        if (index != 0)     // If first elem, don't show this part
        {
        p.Commands.Add(new UICommand { Label = "Bring to top", Id = 2 });
        p.Commands.Add(new UICommand { Label = "Bring up", Id = 3 });
        }
        if (index != GearTree[0].GearGroup.Count - 1)   // If last elem, don't show this part
        {
        p.Commands.Add(new UICommand { Label = "Bring down", Id = 4 });
        p.Commands.Add(new UICommand { Label = "Bring to bottom", Id = 5 });
        }


        // TODO: here happens the ERROR, posibly in new Point(0,0) part
        IUICommand selection = await p.ShowAsync(new Point(0, 0));
        PopupMenu p = new PopupMenu();
        p.Commands.Add(new UICommand { Label = "Delete gear", Id = 0 });
        p.Commands.Add(new UICommand { Label = "-", Id = 1 });

        if (index != 0)     // If first elem, don't show this part
        {
        p.Commands.Add(new UICommand { Label = "Bring to top", Id = 2 });
        p.Commands.Add(new UICommand { Label = "Bring up", Id = 3 });
        }
        if (index != GearTree[0].GearGroup.Count - 1)   // If last elem, don't show this part
        {
        p.Commands.Add(new UICommand { Label = "Bring down", Id = 4 });
        p.Commands.Add(new UICommand { Label = "Bring to bottom", Id = 5 });
        }


        // TODO: here happens the ERROR, posibly in new Point(0,0) part
        IUICommand selection = await p.ShowAsync(new Point(0, 0));