1) Custom DataGrid with CommandBindings.
2) A RoutedCommand Definition.
3) A Command Target Definition. (XAML)
CS :
//(1)
public class CustomDataGrid : DataGrid
{
this.CommandBindings.Add(new CommandBinding(Commands.ClearInputCommand,
ClearFilter, ClearFilterCanExecute));
}
//(2)
public static class Commands
{
public static RoutedCommand ClearInputCommand = new RoutedCommand("ClearInputCommand", typeof(Commands));
}
XAML :
<!-- (3) -->
<local:CustomDataGrid x:Name="grid" />
<Button Command="{x:Static p:Commands.ClearInputCommand}"
CommandTarget="{Binding ElementName=grid}"/>
I would like to transfer the CommandBindings to a child of my CustomDataGrid (an Element in it's Template) , thus dissolving the need for a this "Custom" DataGrid and only a change in a template of a regular DataGrid.
XAML : CustomDataGridTemplate.
<Template TargetType="{x:Type p:CustomDataGrid}" >
......
<p:SomeCustomElement x:Name="I WANT TO BE THE COMMAND TARGET !" />
......
</Template>
how can i achieve this ? is there a was of registering SomeCustomElement to that command ?