English 中文(简体)
在世界森林基金中形成一个完成的环境
原标题:Creating a context menu on drag complete in WPF

我正在研究类似于玛雅高射线的分光,其中我可以把诺德与拖拉和下降联系起来。 由于目标对象可以有数项投入,我想创建一种临时背景标准,以选择投入作为在以下模拟中的建议:

我曾尝试过相当长时间,以启动或开放背景。 它像Win32轨道PopupMenu那样,我所期待的是什么。 是否有WPF/C#等值?

Thanks pixtur

最佳回答

我使用以下法典在一份一览表中附上一个背景:

<ListView ... MouseUp="ListView_MouseUp">

在代码背后一栏中,为显示背景图例:

    private void ListView_MouseUp(object sender, MouseButtonEventArgs e)
    {
        DependencyObject depObj = e.OriginalSource as DependencyObject;

        while (depObj != null && (!(depObj is GridViewColumnHeader)))
        {
            depObj = VisualTreeHelper.GetParent(depObj);
        }            

        if (depObj is GridViewColumnHeader && e.ChangedButton == MouseButton.Left)
        {
            ((GridViewColumnHeader)depObj).ContextMenu = ContextMenu;
        }
    }

The variable ContextMenu refers to a contextmenu instance that i created bfeorehand, you could also create the ContextMenu in the Mouse event handler. I m not sure if this helps as I dont know how you do the drag/drop, but it is worth a try

问题回答

我建议另一种解决办法:

举例来说,一个纽州将提出一条目(Copy)正确点击。 如果点击“Copy”环境菜单项目,则会产生一个ole果。

[..]
var button = new Button();
button.Content = "SomeButtonName";
button.MouseUp += HandleMouseUp;
[..]


private void HandleMouseUp(object sender, MouseButtonEventArgs e)
{
    var senderUIControl = sender as Control;

    var contextMenu = new ContextMenu();

    var item = new MenuItem();
    item.Header = "Copy";
    item.Click += (o, a) => {
        Console.WriteLine("Copy item clicked");
    };
    contextMenu.Items.Add(item);

    senderUIControl.ContextMenu = contextMenu;
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签