tags:

views:

15

answers:

0

My question in short: I want to bind to a Command in a ViewModel associated to a View. The problem is that the place where i bind to the Command is not at the UserControl Level, but deeper.

In long, i have a GridControl (from DevExpress, but it does not matter).

<UserControl>
...
<dxg:GridControl x:Name="grdTrackChanges" DataSource="{Binding TrackChanges}" Height="350">
                <dxg:GridControl.Columns>
                    ....
                </dxg:GridControl.Columns>
                <dxg:GridControl.View>
                <dxg:TableView >
                    <dxg:TableView.RowCellMenuCustomizations>
                        <dxb:BarButtonItem Content="Print" Command="{Binding Path=PrintCommand , RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
                                           CommandParameter="{Binding Path=(dxb:GridPopupMenuBase.GridMenuInfo).Row.RowHandle.Value, RelativeSource={RelativeSource Self}}"/>                     
                    </dxg:TableView.RowCellMenuCustomizations>
                </dxg:TableView>
            </dxg:GridControl.View>
            </dxg:GridControl>

In this line:

Command="{Binding Path=PrintCommand , RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" CommandParameter="{Binding Path=(dxb:GridPopupMenuBase.GridMenuInfo).Row.RowHandle.Value, RelativeSource={RelativeSource Self}}"/> 

The binding to the PrintCommand does not work. Is it right to use the RelativeSource in the Command Binding ?

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.UserControl', AncestorLevel='1''. BindingExpression:Path=PrintCommand; DataItem=null; target element is 'BarButtonItem' (HashCode=15048636); target property is 'Command' (type 'ICommand')

Thanks Jon