简体   繁体   English

如何创建一个上下文菜单,其中包含Gridviewcolumn.celltemplate中的菜单项? 无法获取示例代码

[英]How to Create a context menu which contains menu items in a Gridviewcolumn.celltemplate? Unable to get sample code to work

I have two button inside different columns in data grid view in WPF Application. 我在WPF应用程序的数据网格视图的不同列中有两个按钮。 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. 我有五列,图像显示了我的wpf应用程序的最后两列中的内容。

As we can see in the image, the arrow for the drop down is present in the Location . 正如我们在图像中看到的那样,下拉箭头出现在Location中 But when I press it, I do not see the sub menuitems as shown in the xaml code below. 但是,当我按下它时,看不到下面的xaml代码中所示的子菜单项。

<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>

For some reason, I am unable to see the sub-items Start and Final . 由于某些原因,我看不到子项StartFinal I am very new to this and would appreciate any help. 我对此很陌生,希望能对您有所帮助。

Thanks to all. 谢谢大家。

I am not able to understand how to add a 我无法理解如何添加

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

I want to add something like this in the GridViewColumn.CellTemplate section. 我想在GridViewColumn.CellTemplate部分中添加类似的内容。

Can someone guide me on how to do this. 有人可以指导我如何执行此操作。 I have spent hours but with no success. 我已经花了几个小时,但没有成功。

To resolve the issue, nest it in a Menu tag.

             <Menu>
              <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>
              <Menu>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 GridViewColumn 或 GridViewColumn.CellTemplate 的 GridView 获取项目 - Get items from GridViewColumn or GridViewColumn.CellTemplate of GridView 如何更改用于GridViewColumn的CellTemplate的数据模板 - How to change the Datatemplate which is used for CellTemplate of the GridViewColumn 具有TextBox的GridViewColumn.CellTemplate无法与ListView.ItemContainerStyle一起使用 - GridViewColumn.CellTemplate with TextBox not working with ListView.ItemContainerStyle MultiBinding a TextBlock in a StackPanel in a GridViewColumn.CellTemplate 并且文本不显示 - MultiBinding a TextBlock in a StackPanel in a GridViewColumn.CellTemplate and the Text does not show 从 GridViewColumn 获取 CellTemplate 绑定 - Get CellTemplate binding from GridViewColumn 如何在 wpf 的上下文菜单中创建绑定项目的选择? - How to create a selection of bound items in a context menu in wpf? 通过绑定创建其他上下文菜单项 - Create additional context menu items via binding 如何在单击时创建的“上下文”菜单项中添加组件? - How to add a component to Context menu item which will create on click? Visual Studio扩展:如何获取调用上下文菜单的行? - Visual Studio Extension: How to get the line on which Context Menu was called? 如何将菜单项添加到 Excel 2010 单元格上下文菜单 - 旧代码不起作用 - How to add a menu item to Excel 2010 Cell Context Menu - old code doesn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM