Priority Buttons and Commands

<Button Height="40" Width="40" x:Name="btnup" Command="{Binding UpCommand}" CommandParameter="{Binding ElementName=dgEntities,Path=SelectedItem}" Click="Btnup_OnClick">

What happens with this code is the command that runs after OnClick. Is it possible to execute the Command command first, and then OnClick. Please, help....

+4
source share
1 answer

No, WPF evaluates OnClickbefore being Executecalled in a related command.

Depending on what the click handler does; you can call it instead Executeor return the event back to the view model, which then returns the event back to the view, which then executes the code.

Sort of:

Code-Behind:

  public SomeViewClass
  {
     public SomeViewClass()
     {
         InitializeComponent();

         SomeViewModel viewModel = new SomeViewModel;
         DataContext = viewModel;
         viewModel.SomeCommandCompleted += MoveUp;
     }

     private void MoveUp()
     {
         ...
     }
  }

Show model

public class SomeViewModel
{
    public event Action SomeCommandCompleted;
    public ICommand SomeCommand {get; private set;}

    public SomeViewModel()
    {
        SomeCommand = new DelegateCommand((o) => 
        {
            ...
            if (SomeCommandCompleted != null)
                SomeCommandCompleted();
        }
    }
}
+3
source

All Articles