gpt4 book ai didi

c# - 为什么不显示 ContextMenu(弹出菜单)?

转载 作者:行者123 更新时间:2023-12-03 08:16:25 24 4
gpt4 key购买 nike

以下类派生自 System.Windows.Controls.UserControl。在上述类(class)中,我调用 OpenFileDialog 来打开 XAML 文件(工作流文件)。接下来,我实现了一个鼠标右键单击时的动态菜单。菜单不显示。这是线程问题还是 UI 问题?在我的研究中,我一直无法找到解决方案。

提前致谢。

private void File_Open_Click(object sender, RoutedEventArgs e)
{
var fileDialog = new OpenFileDialog();

fileDialog.Title = "Open Workflow";
fileDialog.Filter = "Workflow| *.xaml";

if (fileDialog.ShowDialog() == DialogResult.OK)
{
LoadWorkflow(fileDialog.FileName);
MouseDown += new System.Windows.Input.MouseButtonEventHandler(mouseClickedResponse);
}
}

private void mouseClickedResponse(object sender, System.Windows.Input.MouseEventArgs e)
{
if (e.RightButton == MouseButtonState.Pressed)
{
LoadMenuItems();
}
}

private void LoadMenuItems()
{
System.Windows.Controls.ContextMenu contextmenu = new System.Windows.Controls.ContextMenu();
System.Windows.Controls.MenuItem item1 = new System.Windows.Controls.MenuItem();
item1.Header = "A new Test";
contextmenu.Items.Add(item1);
this.ContextMenu = contextmenu;
this.ContextMenu.Visibility = Visibility.Visible;
}

最佳答案

我自己遇到过这个问题,我用过这个:

ContextMenu.IsOpen = true;

MSDN Documentation on ContextMenu

关于c# - 为什么不显示 ContextMenu(弹出菜单)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12099282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com