I have the following xaml for a button in the column header of my gridview.
<telerik:GridViewDataColumn Width="auto" > <telerik:GridViewDataColumn.Header> <Button Content="Add New" x:Name="cmdAddNew" Command="{Binding DataContext.AddCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" Margin="0,5,5,5"/> </telerik:GridViewDataColumn.Header></telerik:GridViewDataColumn>
When I run the app I get the following error:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.UserControl', AncestorLevel='1''. BindingExpression:Path=DataContext.AddCommand; DataItem=null; target element is 'Button' (Name='cmdAddNew'); target property is 'Command' (type 'ICommand')
I can't make heads or tails of what is wrong.
The really strange part is if I add a click handler to my view and call:
var vm = (TechniquesViewModel) this.DataContext;
vm.AddCommand.Execute(null);
Everything works perfect.
What am I missing? I know I shouldn't be putting that code in my view, but I can't make it work with the xaml I have.
Thanks ... Ed