shady
shady

Reputation: 1106

Call Method on event in xaml in Xamarin Forms

In WPF I call my Load method like so(using my MainViewModel in the DataContext):

<i:Interaction.Triggers>
    <i:EventTrigger EventName="Loaded" >
        <i:InvokeCommandAction Command="{Binding LoadCommand}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

How can I do something similar in Xamarin Forms? Maybe on the Appearing event? Something like this, except I'm not sure where to go from here.

  <ContentPage.Triggers>
    <EventTrigger Event="Appearing">

    </EventTrigger>
  </ContentPage.Triggers> 

Upvotes: 1

Views: 1470

Answers (1)

eakgul
eakgul

Reputation: 3698

You need to write TriggerAction for that.

Xaml Usage

  <ContentPage.Triggers>
    <EventTrigger Event="Appearing">
      <local:DummyTriggerAction/>
    </EventTrigger>
  </ContentPage.Triggers> 

Trigger Action Class:

public class DummyTriggerAction : TriggerAction<ContentPage>
{
    protected override void Invoke (ContentPage page)
    {
        //do whatever you want
    }
}

Upvotes: 1

Related Questions