My own Triggers

How can I create my own Trigger? For example: how can I do that my created Trigger (like < Mytrigger></ Mytrigger> is active when a bolean is true?

Like this :slight_smile:

public class MyTrigger: Trigger
{
    bool _on;
    public bool On
    {
        get { return _on; }
        set 
        {
            if (_on == value)
                return;
            _on = value;
            if (Node != null)
            {
                if (_on)
                    Activate();
                else
                    Deactivate();
            }
        }
    }


    protected override void OnRooted(Node elm)
    {
        base.OnRooted(elm);
        if (_on)
            BypassActivate();
    }
}

Thanks! Looks like I’ll have to study more c# and One languages because Fuse Rocks! But a basic question… If i have:

void PointerPressed(object sender, PointerPressedArgs args) {

}

In a image, how I active my new Trigger “MyTrigger”?

Depending what on what you want your trigger to do, you can solve this several ways, if you want something to happen in response to PointerPressed I suggest using this setup:

<Image>

    <Pressing>
        ...
    </Pressing>

    or

    <Tapped>
        ...
    </Tapped>

</Image>

or if you want to roll your own triggers and logic:

<Image>

    <MyTrigger>
        ...
    </MyTrigger>

</Image>

and

public class MyTrigger : Trigger
{

    protected override void OnRooted(Node elm)
    {
        Pointer.Pressed.AddHandler(elm, OnPointerPressed);
        base.OnRooted(elm);
    }

    protected override void OnUnrooted(Node elm)
    {
        Pointer.Pressed.RemoveHandler(elm, OnPointerPressed);
        base.OnUnrooted(elm);
    }

    void OnPointerPressed(object sender, PointerPressedArgs args)
    {
        Activate();
    }

}

You can also use ManualTrigger

<Image>

  <ManualTrigger ux:Name="ManTrigger">
      <Change .... />
  </ManualTrigger>

</Image>

And from code behind trigger it by ManTrigger.On = true

Thanks Håvard Homb that’s what I was looking for. But it does not work for me.

I have this… In the UX file:


 < Image Pointer.Pressed="ActivarInput" File="">
 < ManualTrigger ux:Name="TriggerAccion">

 < Move RelativeTo="Size" Target="quepelicula" Y="-1.45" Easing="ElasticOut" EasingBack="ElasticIn" Duration="1" Delay="0.3" />

 < /ManualTrigger>
 < /Image>
 

And in the Uno file:


public partial class MyApp
{

    void ActivarInput(object sender, PointerPressedArgs args)
{
    TriggerAccion.On = true;
}

}

And nothing happen!

I build my project for IOS and the ManualTrigger Works! In the preview windows of Fuse dont do anything! Is a bug of the beta version or Im doing something wrong?

Could it be that you are previewing the app in the automatically refreshed “edit mode” (by doubleclicking on the .ux file, or chosing “Open” from the context menu)? If so then your codebehind is not executed.

It should work if you use the regular preview instead, i.e. by selecting the .ux file and picking “Preview” in the context menu.

You can read a bit more about the 2 different modes here: https://www.fusetools.com/developers/guides/topics/buildanddeploy/fuse

Thanks! Problem solved!