删除事件未在wpf上下文菜单上触发

时间:2017-11-08 14:22:45

标签: c# wpf

我一直试图将我的应用程序中的一些信息拖到按钮的子菜单中。

我可以将信息放在系统上的任何元素中,但它不能在我使用上下文菜单创建的子菜单上工作。

我使用文本框和带有上下文菜单的按钮创建了一个示例。

当我尝试拖动文本并将其放在上下文菜单项中时,不会触发drop事件。

你们有什么想法会发生什么事吗?

的Xaml:

<Button Height="30" Width="72" HorizontalAlignment="Left" AllowDrop="True" DragEnter="Button_DragEnter" >
    Context
    <Button.ContextMenu>
        <ContextMenu AllowDrop="True">
            <MenuItem Header="Text1" AllowDrop="True" Drop="MenuItem_Drop" />
            <MenuItem Header="Text2" AllowDrop="True" Drop="MenuItem_Drop" />
            <MenuItem Header="Text3" AllowDrop="True" Drop="MenuItem_Drop" />
        </ContextMenu>
    </Button.ContextMenu>

</Button>

C#:

private void Button_DragEnter(object sender, DragEventArgs e)
{
    Button bt = sender as Button;
    if (!bt.ContextMenu.IsOpen)
        bt.ContextMenu.IsOpen = true;
}
private void MenuItem_Drop(object sender, DragEventArgs e)
{
    MenuItem menuItem = sender as MenuItem;
    MessageBox.Show("Drop on the" + menuItem.Header + " data = " + e.Data.GetData(typeof(string)));
}

OBS:当我从我的应用程序外部拖动时,拖放效果很好

0 个答案:

没有答案