Skip to content

CallMethodAction

Jon W Chu edited this page Nov 16, 2015 · 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.

Sample Code:

XAML

<Button x:Name="button">
    <Interactivity:Interaction.Behaviors>
        <Interactions:EventTriggerBehavior EventName="Click" SourceObject="{Binding ElementName=button}">
            <Interactions:CallMethodAction TargetObject="{Binding}" MethodName="IncrementCount"/>
        </Interactions:EventTriggerBehavior>
    </Interactivity:Interaction.Behaviors>
</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));
}