Triggers, actions & behaviors in XAML
Upcoming SlideShare
Loading in...5
×
 

Triggers, actions & behaviors in XAML

on

  • 4,411 views

Triggers, actions & behaviors in XAML

Triggers, actions & behaviors in XAML

Statistics

Views

Total Views
4,411
Views on SlideShare
4,411
Embed Views
0

Actions

Likes
1
Downloads
32
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Triggers, actions & behaviors in XAML Triggers, actions & behaviors in XAML Presentation Transcript

  • Triggers, Actions& Behaviors Eyal Vardi CEO E4D Solutions LTD Microsoft MVP Visual C# blog: www.eVardi.com
  • Agenda  Actions  Triggers  Behaviors© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 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
  • .NET 3.5 WPF ( When __, Do __ )© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 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
  • Perform on somebody else© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • Action© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 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
  • 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
  • Custom Trigger© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 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
  • 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
  • Behaviors© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • Blend Behaviors© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 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
  • Fluid Move Behavior© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • Fluid Move Behavior© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 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
  • Fluid Layout in VSM© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • 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
  • Layout States & Transition© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • FluidMoveTagSetBehavior© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il
  • Fluid Move Tag Set Behavior© 2008 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: Eyal@E4D.co.il