[英]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 . 由于某些原因,我看不到子项Start和Final 。 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.