# My own Triggers

**URL:** <https://forums.fusetools.com/t/my-own-triggers/5030>\
**Category:** How-to Discussions\
**Created:** [April 18, 2015, 3:51pm UTC](https://forums.fusetools.com/t/my-own-triggers/5030 "2015-04-18T15:51:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cristian\_Karmy1](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/cristian_karmy1/32/480_2.png) [@Cristian\_Karmy1](https://forums.fusetools.com/u/Cristian_Karmy1)\
**Post date:** [April 18, 2015, 3:51pm UTC](https://forums.fusetools.com/t/my-own-triggers/5030/1 "2015-04-18T15:51:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [April 18, 2015, 4:35pm UTC](https://forums.fusetools.com/t/my-own-triggers/5030/2 "2015-04-18T16:35:57Z")

</div>

Like this 🙂

```auto
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();
    }
}

```

---

<div class="post-metadata">

**Author:** ![Cristian\_Karmy1](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/cristian_karmy1/32/480_2.png) [@Cristian\_Karmy1](https://forums.fusetools.com/u/Cristian_Karmy1)\
**Post date:** [April 18, 2015, 7:02pm UTC](https://forums.fusetools.com/t/my-own-triggers/5030/3 "2015-04-18T19:02:17Z")

</div>

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”?

---

<div class="post-metadata">

**Author:** ![Vegard\_Strand\_Lende](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/vegard_strand_lende/32/349_2.png) [@Vegard\_Strand\_Lende](https://forums.fusetools.com/u/Vegard_Strand_Lende)\
**Post date:** [April 19, 2015, 12:12pm UTC](https://forums.fusetools.com/t/my-own-triggers/5030/4 "2015-04-19T12:12:56Z")

</div>

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:

```auto
<Image>

    <Pressing>
        ...
    </Pressing>

    or

    <Tapped>
        ...
    </Tapped>

</Image>

```

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

```auto
<Image>

    <MyTrigger>
        ...
    </MyTrigger>

</Image>

```

and

```auto
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();
    }

}

```

---

<div class="post-metadata">

**Author:** ![Havard\_Homb](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/havard_homb/32/229_2.png) [@Havard\_Homb](https://forums.fusetools.com/u/Havard_Homb)\
**Post date:** [April 19, 2015, 12:20pm UTC](https://forums.fusetools.com/t/my-own-triggers/5030/5 "2015-04-19T12:20:18Z")

</div>

You can also use ManualTrigger

```auto
<Image>

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

</Image>

```

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

---

<div class="post-metadata">

**Author:** ![Cristian\_Karmy1](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/cristian_karmy1/32/480_2.png) [@Cristian\_Karmy1](https://forums.fusetools.com/u/Cristian_Karmy1)\
**Post date:** [April 19, 2015, 3:50pm UTC](https://forums.fusetools.com/t/my-own-triggers/5030/6 "2015-04-19T15:50:36Z")

</div>

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:

```auto

 < 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:

```auto

public partial class MyApp
{

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

}

```

And nothing happen!

---

<div class="post-metadata">

**Author:** ![Cristian\_Karmy1](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/cristian_karmy1/32/480_2.png) [@Cristian\_Karmy1](https://forums.fusetools.com/u/Cristian_Karmy1)\
**Post date:** [April 19, 2015, 3:54pm UTC](https://forums.fusetools.com/t/my-own-triggers/5030/7 "2015-04-19T15:54:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Remi\_Pedersen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/remi_pedersen/32/432_2.png) [@Remi\_Pedersen](https://forums.fusetools.com/u/Remi_Pedersen)\
**Post date:** [April 19, 2015, 8:28pm UTC](https://forums.fusetools.com/t/my-own-triggers/5030/8 "2015-04-19T20:28:59Z")

</div>

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](https://www.fusetools.com/developers/guides/topics/buildanddeploy/fuse)

---

<div class="post-metadata">

**Author:** ![Cristian\_Karmy1](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/cristian_karmy1/32/480_2.png) [@Cristian\_Karmy1](https://forums.fusetools.com/u/Cristian_Karmy1)\
**Post date:** [April 20, 2015, 1:08am UTC](https://forums.fusetools.com/t/my-own-triggers/5030/9 "2015-04-20T01:08:22Z")

</div>

Thanks! Problem solved!
