Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Binding Buttons directly to DataPresenterCommands?
posted

Hi from germany,

i understand that i can execute DataPresenterCommans from within a Button_Clicked Eventhandler using the following Syntax:

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
   xamGrid.ExecuteCommand(DataPresenterCommands.RecordFirstOverall);
}

However, this way the Button will not get disabled, when a Command is not available (Commands CanExecute() Method returns false).
Is there a way to bind a Button DIRECTLY to a DataPresenter Command?

button.Command = DataPresenterCommands.RecordFirstOverall;


  • 1990
    Verified Answer
    posted

    Hi Vjarai,

    You can bind the button directly in XAML like this:

    <Button

                  Command="{x:Static igDP:DataPresenterCommands.RecordFirstOverall}"
                  CommandTarget="{Binding ElementName=xamGrid}"
                  Content="RecordFirstOverall"
                  Width="Auto"
                  Height="20"
                  HorizontalAlignment="Left"/>

     

    You can see the example in the samples - Feature Browser -> XamDataGrid -> Data Binding and Interaction -> XamDataGrid Commands.

    Sincerely,

    Horen Kirazyan