5
9

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.

意外と知られていない?EventTriggerとChangePropertyActionの組み合わせ

Last updated at Posted at 2015-10-07

概要

XAMLを独自にインタラクティブにしようと思うとInteraction.Triggersの利用は避けて通れません。
EventTriggerを使って、特定のイベントが発生したときに、要素のプロパティを変更しようとして検索をすると、不思議な事に何故かChangePropertyActionに中々辿りつけません。
プロパティを変更したいだけなのに、Storyboardを使用する方法ばかりがヒットします。
ChangePropertyActionは、Blend SDKとして配布されているのが関係しているのかも知れません。
ただ、Blend SDKを忌避する理由も見当たらないので、備忘録として残します。

サンプル

<Window
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
  xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
  x:Class="Sample.MainWindow" x:Name="root"
  Height="350" Width="525">

    <i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseLeftButtonDown">
     <ei:ChangePropertyAction 
                      TargetName="root" 
             PropertyName="Background"
             Value="Red">
      </ei:ChangePropertyAction>
     </i:EventTrigger>
    </i:Interaction.Triggers>
</Window>
5
9
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
5
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?