如何在gridviewcolumn.celltemplate中创建包含菜单项的上下文菜单? [英] How to create a context menu which contains menu items in a gridviewcolumn.celltemplate?

查看:89
本文介绍了如何在gridviewcolumn.celltemplate中创建包含菜单项的上下文菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF应用程序的数据网格视图中的不同列中有两个按钮。该数据网格视图将从DB加载。同时,每行中都会有一个位置下拉菜单项。我有五列,图像显示了我的wpf应用程序的最后两列中的内容。



像这样



正如我们在图像中看到的那样,下拉的箭头出现在位置中。但是当我按下它时,我没有看到下面的xaml代码中显示的子菜单项。

I have two button inside different columns in data grid view in WPF Application. That data grid view will load from DB. At same time , there will be a Location drop down menu item present in each row. I have five columns and the image shows the contents present in the last two column of my wpf application.

Like this

As we can see in the image, the arrow for the drop down is present in the Location. But when I press it, I do not see the sub menuitems as shown in the xaml code below.

<local:CustomListView.View>
    <GridView AllowsColumnReorder="False">
        <GridViewColumn Header="Car" Width="Auto" 
                        DisplayMemberBinding="{Binding Car}" />
        <GridViewColumn Header="House" Width="Auto" 
                        DisplayMemberBinding="{Binding House}" />
        <GridViewColumn Header="" Width="60">
            <GridViewColumn.CellTemplate>
                <DataTemplate>
                    <MenuItem Header="Location" ToolTip="Click to see info">
                        <MenuItem Header="Start" Click="info_Click" 
                                  ToolTip="Shows the start route"/>
                        <MenuItem Header="Final" Click="info_Click" 
                                  ToolTip="Show the final route"/>
                    </MenuItem>
                </DataTemplate>
            </GridViewColumn.CellTemplate>
        </GridViewColumn> 
    </GridView>
</local:CustomListView.View>

出于某种原因,我无法看到子项Start和Final。我是新手,非常感谢任何帮助。



感谢所有人。



我是无法理解如何添加下面显示的以下代码部分以获得菜单项。有可能还是有其他方法?

For some reason, I am unable to see the sub-items Start and Final. I am very new to this and would appreciate any help.

Thanks to all.

I am not able to understand how to add the following code section shown below to have a menu item. Is it possible or is there any other approach?

<local:CustomListView.ContextMenu>
    <ContextMenu>    
    //I want to be able to place the MenuItem in here
    </ContextMenu>
</local:CustomListView.ContextMenu>

我想在GridViewColumn.CellTemplate部分添加类似的东西。



有人可以指导我如何做到这一点。我花了几个小时但没有成功。



我尝试过的事情:



上面显示的代码部分就是我试过的。

I want to add something like this in the GridViewColumn.CellTemplate section.

Can someone guide me on how to do this. I have spent hours but with no success.

What I have tried:

The code sections shown above is what I have tried.

推荐答案

你不清楚这个上下文菜单应该去哪里。 />


网格?页眉?单元格?



无论如何,你不要模板菜单。 单元具有附加菜单的东西(例如文本块)。在您的情况下,您甚至没有将列绑定到任何内容。



抛出自定义数据网格,直到你可以得到一个常规数据网格来做你想做的事情:菜单。



WPF ContextMenu - 完整的WPF教程 [ ^ ]
You're not clear on "where" this context menu is supposed to go.

Grid? Header? Cell?

In any event, you don't "template a menu". The "cell" has something (e.g. a textblock) to which the menu is attached. In your case, you're not even binding the column to anything.

And toss the "custom" datagrid until you can get a "regular" datagrid to do what you want re: menus.

The WPF ContextMenu - The complete WPF tutorial[^]


这篇关于如何在gridviewcolumn.celltemplate中创建包含菜单项的上下文菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆