Skip to content

CallMethodAction

branh edited this page Dec 3, 2018 · 3 revisions

CallMethodAction represents an action which, when triggered, calls a method on a specified object.

Using this Behavior allows the specified MethodName to be called on TargetObject.

SampleCode:

XAML

<Button x:Name="button">
  <Behaviors:Interaction.Triggers>
    <Behaviors:EventTrigger EventName="Click" SourceObject="{Binding ElementName=button}">
      <Behaviors:CallMethodAction TargetObject="{Binding}" MethodName="IncrementCount"/>
    </Behaviors:EventTrigger>
  </Behaviors:Interaction.Triggers>
</Button>

C#

public int Count { get; set; }

public event PropertyChangedEventHandler PropertyChanged;

public void IncrementCount()
{
  Count++;
  OnPropertyChanged(nameof(Count));
}

private void OnPropertyChanged(string propertyName)
{
  PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}