1
votes

I have this DevExpress GridControl that is dynamically created using a CellTemplateSelector. One of the GridControl columns is defined by a DataTemplate that appears as follows:

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

There exists a class called DataGridRow, that contains properties for ONE row of GridControl data. This class also contains a command defined as

    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
    }

As shown above, the ComboBoxEdit SelectedItem and ItemsSource properties are bound to DataGridRow properties accessed via the RowData.Row property, and the DeleteNameCommand is also accessible via the RowData.Row property.

When the user clicks the ComboBoxEdit down-arrow, the list of Names is displayed, and when the user right-clicks a list name, the context menu is displayed. Since the PopupMenu/BarButtonItem is not part of the Visual Tree, how would I bind the BarButtonItem Command property to the RowData.Row property accessed in the ComboBoxEdit? ... and how could I pass the text of the ComboBoxEdit list item that was right-clicked as the value of the CommandParameter?

Any pointers to the right direction are very much appreciated.

1

1 Answers

1
votes

OK ... after days of trying to figure this out, the great people at DevExpress were able to provide me with a solution. My apologies for posting the question as I did not expect (my bad) to get a solution so quickly (I asked them yesterday afternoon), but I thought it useful to inform the community of the solution.

The ComboBoxEdit editor data context is accessible via

(dxe:BaseEdit.OwnerEdit).DataContext

and to access the associated RowData.Row property, which itself contains the properties usable for each row column, is accessible via

(dxe:BaseEdit.OwnerEdit).DataContext.RowData.Row

SO, it follows that the PopupMenu/BarButtonItem Command can be bound to the DeleteNameCommand contained in the DataGridRow class, which itself is accessible via RowData.Row by specifying the following:

Command="{Binding Path=(dxe:BaseEdit.OwnerEdit).DataContext.RowData.Row.DeleteNameCommand, RelativeSource={RelativeSource Self}}"

... and the text of the ComboBoxEdit list item that was right-clicked is available to pass as the value for CommandParameter via the following declaration:

CommandParameter="{Binding}"

... and there was much rejoicing :-)