More Related Content Similar to Triggers, actions & behaviors in XAML (20) More from Eyal Vardi (20) Triggers, actions & behaviors in XAML2. Agenda
Actions
Triggers
Behaviors
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
3. Old WPF ( No Silverlight )
<Button Content="Click Me">
<Button.Triggers>
<EventTrigger RoutedEvent="Click">
<EventTrigger.Actions>
<BeginStoryboard Storyboard="{StaticResource sbSpin}"/>
</EventTrigger.Actions>
</EventTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="Content" Value="{x:Null}" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Yellow" />
</MultiTrigger>
</Button.Triggers>
</Button>
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
4. .NET 3.5 WPF ( When __, Do __ )
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
5. Action Way
<Button Content="Click Me">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<E4D:MyAction TargetName="lbTrace" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
public class MyAction : TargetedTriggerAction<DependencyObject>
{
public MyAction() { ... }
protected override void Invoke(object o) { ... }
}
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
6. Perform on
somebody else
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
8. Trigger ( When )
Invokes a bunch of actions at a point when it
decides to do that.
Event Trigger
Timer Trigger
Size Trigger
The Attach & Detach connect to
the target.
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
9. Timer Trigger Sample
public class TimerTrigger : TriggerBase<DependencyObject>
{
public TimeSpan Interval { get; set; }
protected override void OnAttached()
{
timer = new DispatcherTimer();
timer.Interval = Interval;
timer.Tick += OnTick; timer.Start();
}
void OnTick(object sender, EventArgs e)
{
this.InvokeActions(null);
}
protected override void OnDetaching()
{
timer.Tick -= OnTick; timer = null;
}
DispatcherTimer timer;
}
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
11. Behavior
Behavior don’t need the “When” ( Trigger ),
and don’t have the Invoke.
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
12. Behavior with Command
public class MethodBehavior : Behavior<DependencyObject>
{
public ICommand Command { get; set; }
public MethodBehavior()
{
Command = new ActionCommand( MyMethod );
}
private void MyMethod()
{ <Button Content="Click Me“>
// TODO: <i:Interaction.Behaviors>
} <E4D:MethodBehavior>
} <i:Interaction.Triggers>
<i:KeyTrigger SourceName="...">
<i:InvokeCommandAction CommandName="Command" />
</i:KeyTrigger>
</i:Interaction.Triggers>
</E4D:MethodBehavior>
</i:Interaction.Behaviors>
</Button>
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
15. Fluid Move Behavior
Behavior that watches an element (or a set of
elements) for layout changes, and moves the
element smoothly to the new position when
needed.
<ei:FluidMoveBehavior Duration="00:00:01" AppliesTo="Children">
<ei:FluidMoveBehavior.EaseY>
<BackEase EasingMode="EaseOut" Amplitude="0.5"/>
</ei:FluidMoveBehavior.EaseY>
<ei:FluidMoveBehavior.EaseX>
<BackEase EasingMode="EaseOut" Amplitude="0.5"/>
</ei:FluidMoveBehavior.EaseX>
</ei:FluidMoveBehavior>
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
18. Fluid Layout in VSM
Animation between states.
- Transition Effect
- Easing Function
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
19. Fluid Layout in VSM
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
20. Layout States & Transition
Layout States animate the state changes for
you at the appropriate times, as your items are
added to or removed from the list.
Edit the ItemContainerStyle and ItemsPanel.
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
21. Layout States & Transition
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
23. Fluid Move Tag Set
Behavior
© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il