【发布时间】:2018-06-26 14:51:38
【问题描述】:
我有这个使用 CellTemplateSelector 动态创建的 DevExpress GridControl。 GridControl 列之一由如下所示的 DataTemplate 定义:
<DataTemplate x:Key="NameComboColumnTemplate">
<ContentControl>
<dxg:GridColumn
x:Name="GridColumnName"
FieldName="{Binding Path=(dxci:DependencyObjectExtensions.DataContext).FieldName, RelativeSource={RelativeSource Self}}"
Header="{Binding Path=(dxci:DependencyObjectExtensions.DataContext).Header, RelativeSource={RelativeSource Self}}"
Width="{Binding Path=(dxci:DependencyObjectExtensions.DataContext).Width, RelativeSource={RelativeSource Self}}">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:ComboBoxEdit
IsTextEditable="False"
SelectedItem="{Binding RowData.Row.SelectedCylinderName, Mode=TwoWay}"
ItemsSource="{Binding RowData.Row.NameList, Mode=TwoWay}">
<dxe:ComboBoxEdit.ItemContainerStyle>
<Style TargetType="dxe:ComboBoxEditItem">
<Setter Property="dxb:BarManager.DXContextMenu">
<Setter.Value>
<dxb:PopupMenu>
<dxb:BarButtonItem
x:Name="BarButtonItemName"
Content="Delete"
Command="{Binding DeleteNameCommand}"
CommandParameter="{Binding}"/>
</dxb:PopupMenu>
</Setter.Value>
</Setter>
</Style>
</dxe:ComboBoxEdit.ItemContainerStyle>
</dxe:ComboBoxEdit>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
</ContentControl>
</DataTemplate>
存在一个名为 DataGridRow 的类,它包含 GridControl 数据的一行的属性。该类还包含一个定义为
的命令 public ICommand DeleteNameCommand => new DelegateCommand<object>(obj => DeleteName(obj));
private void DeleteName(object obj)
{
// the obj parametercontains the text present on the ComboBoxEdit list item that was
// right-clicked to display the context menu.
// Delete the name from the list here
}
如上所示,ComboBoxEdit SelectedItem 和 ItemsSource 属性绑定到通过 RowData.Row 属性访问的 DataGridRow 属性, strong>DeleteNameCommand 也可以通过 RowData.Row 属性访问。
当用户单击 ComboBoxEdit 向下箭头时,会显示名称列表,当用户右键单击列表名称时,会显示上下文菜单。由于 PopupMenu/BarButtonItem 不是可视树的一部分,我如何将 BarButtonItem Command 属性绑定到在 ComboBoxEdit 中访问的 RowData.Row 属性? ...以及如何将右键单击的 ComboBoxEdit 列表项的文本作为 CommandParameter 的值传递?
非常感谢任何指向正确方向的指针。
【问题讨论】:
标签: binding contextmenu devexpress-wpf