WPF DataGrid Binding with Context Menu argument

Aug 7 2014 10:12 AM
I have a ContextMenu inside DataGrid, I need to pass the selected items, selected cells as an argument to my Delegate comments. When i try with the following code. i am getting an BindingError as "Cannot find source for binding with reference 'ElementName=m_dsGrid'. BindingExpression:Path=SelectedItems.Cells; DataItem=null; target element is 'MenuItem' (Name=''); target property is 'CommandParameter' (type 'Object')"
 
<dp:XamDataGrid DataSource="{Binding CustomerCollection}" IsSynchronizedWithCurrentItem="True" GroupByAreaLocation="None"
ActiveDataItem="{Binding SelectedCustomer, UpdateSourceTrigger=PropertyChanged, Source=.}">
<dp:XamDataGrid.FieldLayoutSettings>
<dp:FieldLayoutSettings AutoGenerateFields="False" SelectionTypeRecord="Single" AllowFieldMoving="No" AllowRecordFixing="No" RecordSelectorLocation="None"/>
</dp:XamDataGrid.FieldLayoutSettings>
<dp:XamDataGrid.FieldSettings>
<dp:FieldSettings AllowResize="False" CellClickAction="SelectRecord" LabelTextAlignment="Center" AllowEdit="False"/>
</dp:XamDataGrid.FieldSettings>
<dp:XamDataGrid.FieldLayouts>
<dp:FieldLayout Key="Details">
<dp:FieldLayout.Fields>
<dp:UnboundField Label="No" BindingPath="Number" Width="80"/>
<dp:UnboundField Label="Name" BindingPath="Name" Width="80"/>
<dp:UnboundField Label="Place" BindingPath="Place" Width="80"/>
</dp:FieldLayout.Fields>
</dp:FieldLayout>
</dp:XamDataGrid.FieldLayouts>
<dp:XamDataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy">
<MenuItem Header="Copy selected cells" Command="{Binding Path=CopySelectedCellsCommand}" CommandParameter="{Binding ElementName=m_dsGrid, Path=SelectedItems.Cells}" ToolTip="Reload current column layout from database.">
</MenuItem>
</ContextMenu>
</dp:XamDataGrid.ContextMenu>
</dp:XamDataGrid>
 

Answers (1)