Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind Events to Commands

Tags:

c#

mvvm

wpf

Without the use of third part DLLs, is it possible to bind the event of CellEditEnding to my command? Currently, I am using .NET 3.5, which has become an issue because it tells me that I cannot add an EventTrigger to the Trigger collection.

<i:Interaction.Triggers>
    <i:EventTrigger EventName="CellEditEnding">
        <i:InvokeCommandAction CommandName="EnterUserCountCommand" />
    </i:EventTrigger>
</i:Interaction.Triggers>

Any help would be greatly appreciated!

like image 342
Nerd in Training Avatar asked Nov 25 '25 18:11

Nerd in Training


1 Answers

Not sure if this is the best solution, but when I'm in this situation I usually just do something like this.

private void CellEditEndingEvent(object sender, RoutedEventArgs e)
{
    var viewModel = (MyViewModel)DataContext;
    //Change params as needed
    if (viewModel.MyCommand.CanExecute(null))
        viewModel.MyCommand.Execute(null);
}
like image 137
Kevin DiTraglia Avatar answered Nov 28 '25 06:11

Kevin DiTraglia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!