Reputation: 13
I know the Answer is maybe very simple, but i don't understand this whole Visual Tree thing just jet.
I have a WPF Page as a View, bound to a VM. In the Page is a Data Grid with Headers. One of the Headers has a Button Inside, grouped in a Stack Panel. I now try to Bind the Command of the Button to an ICommand in the VM, but cant figure out how.Data Context of the Page is set to The VM in XAML.
Binding something from the VW to the Data Grid itself, works just fine.
For Example:
ItemsSource="{Binding ObcRgListView, UpdateSourceTrigger=PropertyChanged}"
For binding a Command to a Button inside a DataGridTemplateColumn i use:
Command="{Binding Path=DataContext.CmdChangeStatus,RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
which also works fine.
But if i now try to bind a Command to a Button inside a Header of said Data Grid, i get the Binding Error:
Quelle nicht gefunden: RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1'
Maybe someone can help me out here an explain the difference between DataGridHeader and DataGridTemplateColumn.
Thanks and Greetings from Swizerland
Upvotes: 0
Views: 18