2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UWPでEventTriggerを使う

Posted at

#概要
 UWPでEventTriggerを使おうと思ったら、ちょっと手間取ったので手順を残します。

#導入
 WPFではBlendの中のライブラリを参照したりしました。UWPではNugetでBehaviorsというライブラリを使います。

##Nuget
 Nugetで次のどちらかを入手します

  • Microsoft.Xaml.Behaviors.Uwp.Native
  • Microsoft.Xaml.Behaviors.Uwp.Managed

##XAML側準備
 そして、WPFのときと同じように名前空間をxamlに追加します

xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" 
xmlns:Interactions="using:Microsoft.Xaml.Interactions.Core"

##EventTrigger追加

<Button x:Name="button1">
    <Interactivity:Interaction.Behaviors>
        <Interactions:EventTriggerBehavior EventName="Click" SourceObject="{Binding ElementName=button1}">
            <Interactions:InvokeCommandAction Command="{Binding UpdateCountCommand}"/>
        </Interactions:EventTriggerBehavior>
    </Interactivity:Interaction.Behaviors>
</Button>

##その他
 このライブラリは色々な機能があるっぽいので、活用しましょう(他人任せ)。

#参考

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?