SlideShare una empresa de Scribd logo
1 de 25
Silverlight’s Visual State Manager




                            Jeremy Likness
                            Project Manager, Senior Consultant
                            jlikness@wintellect.com
                                                                   Copyright © 2011




consulting   training   design   debugging                       wintellect.com
what we do
    consulting     training    design     debugging

 who we are
   Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins –
   we pull out all the stops to help our customers achieve their goals through advanced
   software-based consulting and training solutions.

 how we do it                                           Training
                                                        •   On-site instructor-led training
   Consulting & Debugging                               •   Virtual instructor-led training
   •   Architecture, analysis, and design services      •   Devscovery conferences
   •   Full lifecycle custom software development
   •   Content creation                                 Design
   •   Project management                               •   User Experience Design
   •   Debugging & performance tuning                   •   Visual & Content Design
                                                        •   Video & Animation Production


consulting    training    design     debugging                                   wintellect.com
Agenda
 •   XAML
 •   Dependency Properties
 •   Coercion
 •   Storyboards
 •   “Lookless” Controls
 •   Parts and States
 •   Groups
 •   States
 •   Transitions
 •   Demo: Visual State Explorer
 •   Visual State Manager
 •   Visual State Aggregator
 •   Demo: MVVM with Visual States



consulting   training   design   debugging   wintellect.com
XAML
 • Extensible Application Markup Language
 • Declarative:
      – Initialize objects
      – Set properties of objects
 •   Object graph
 •   Behaviors
 •   Triggers
 •   Data-binding – clean separation of UI layer


consulting   training   design   debugging         wintellect.com
XAML

                             Rectangle Type is Initialized

 <Rectangle
   Name="rectangle1"
   Width="100"                   Complex Dependency Property Value
   Height="100">
   <Rectangle.Fill>
     <SolidColorBrush Color="Blue"/>
   </Rectangle.Fill>
 </Rectangle>
                                        Type Converter




consulting   training   design   debugging                   wintellect.com
Dependency Properties
 •   Actual value based on multiple inputs
 •   Callback functionality
 •   Required for animation
 •   Backed by CLR properties
 •   CLR wrapper (get/set)
 •   Styles
 •   Data-binding



consulting   training   design   debugging   wintellect.com
Dependency Properties

 public static readonly DependencyProperty
        IsSpinningProperty =                  Backing Store
     DependencyProperty.Register(
               "IsSpinning", typeof(Boolean),
               typeof(SilverlightExampleClass), null);

                                             CLR Property Façade
 public bool IsSpinning
 {
     get { return (bool)GetValue(IsSpinningProperty); }
     set { SetValue(IsSpinningProperty, value); }
 }




consulting   training   design   debugging                         wintellect.com
Coercion

 • How do we compute the value of a
   dependency property?
 • Value Precedence…
 1.   Active animations (storyboard not stopped)
 2.   Local value (SetValue)
 3.   Template (ControlTemplate, DataTemplate)
 4.   Style
 5.   Default value

consulting   training   design   debugging    wintellect.com
Storyboards

 •   Coerce property values
 •   May transition over time
 •   Can be cyclical
 •   “Ending” not the same as “Stopping”
 •   Key-frame vs. From/To/By
 •   Color, Double, Point, Object



consulting   training   design   debugging   wintellect.com
Storyboards
 <StackPanel x:Name="LayoutRoot" Background="White">      Range
     <StackPanel.Resources>
         <Storyboard x:Name="myStoryboard">
             <DoubleAnimation From="30" To="200" Duration="00:00:3"
                 Storyboard.TargetName="myRectangle"
                 Storyboard.TargetProperty="Height">
                                                               Target
                 <DoubleAnimation.EasingFunction>
                     <BounceEase Bounces="2" EasingMode="EaseOut"
                                 Bounciness="2" />
                 </DoubleAnimation.EasingFunction>           Easing
             </DoubleAnimation>
         </Storyboard>
     </StackPanel.Resources>
     <Rectangle x:Name="myRectangle"
 MouseLeftButtonDown="Mouse_Clicked"
      Fill="Blue" Width="200" Height="30" />
 </StackPanel>




consulting   training   design   debugging                  wintellect.com
“Lookless” Controls

 • Custom controls separate logic from visual
   appearance
 • Allows modifying visual appearance without
   changing underlying code
 • Styles
 • Templates
 • “Control Contract” – parts and states


consulting   training   design   debugging   wintellect.com
Parts and States

 • Parts – named sections within the control




 • States – change appearance based on
   context



consulting   training   design   debugging   wintellect.com
Groups

 • Set of mutually exclusive states for a control
 • Orthogonal
 • Controls may have multiple states, but only
   one state per group
 • Example: CheckBox
      –   CommonStates (Normal, MouseOver, Pressed, etc.)
      –   CheckStates (Checked, Unchecked, InDeterminate)
      –   FocusStates
      –   ValidationStates

consulting   training   design   debugging           wintellect.com
States

 • Appearance of control in a particular state
 • “Base” state means “no state”
 • Typically you will add a default state and set
   the control to that state, i.e. “Normal”
 • States are created by a storyboard
 • The storyboard plays and may have
   animation but is not stopped until the state
   within that group changes

consulting   training   design   debugging   wintellect.com
States
 <ControlTemplate TargetType="Button">
   <Grid >                                            Root Visual
     <VisualStateManager.VisualStateGroups>
       <VisualStateGroup x:Name="CommonStates">             Group
         <VisualState x:Name="Normal" />
 <VisualState x:Name="MouseOver">                      Default State
           <Storyboard>
             <ColorAnimation Storyboard.TargetName="ButtonBrush“
 Storyboard.TargetProperty="Color" To="Red" />
           </Storyboard>
         </VisualState>
                                               Storyboard & Animation
       </VisualStateGroup>
     </VisualStateManager.VisualStateGroups>
     <Grid.Background>
       <SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
     </Grid.Background>
   </Grid>
 </ControlTemplate>


consulting   training   design   debugging                   wintellect.com
Transitions
 • Control transition between one state to another
 • Generated duration will automatically transition
   between old storyboard and new storyboard
 • Control isn’t in the “new” state until the transition
   completes
 • New storyboard gives more control (this is
   stopped once the transition completes)
 • Stop old storyboard > start transition storyboard
   > stop transition storyboard > start new
   storyboard
consulting   training   design   debugging       wintellect.com
Transitions                                         Uses State Storyboard


 <VisualStateGroup.Transitions>
     <VisualTransition To="GreenState" GeneratedDuration="0:0:1“/>
     <VisualTransition From="GreenState" To="ShowState">
         <Storyboard Duration="0:0:1">
             <DoubleAnimation                  Uses Transition Storybard
                 Storyboard.TargetName="LayoutRoot"
 Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.R
 otationY)"
                 From="-80" To="-0"/>
             <DoubleAnimation
                 Storyboard.TargetName="LayoutRoot"
 Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTra
 nsform.X)"
                 From="-205" To="0"/>
         </Storyboard>
     </VisualTransition>
 </VisualStateGroup.Transitions>



consulting   training   design   debugging                    wintellect.com
Demo
   Visual State Explorer




consulting   training   design   debugging   wintellect.com
Visual State Manager
 • Manages all logic and transitions
 • GetVisualStateGroups – iterate all groups in the
   control
      – Iterate states and transitions within the group
      – CurrentState, CurrentStateChanging, CurrentStateChang
        ed
      – Use state/transition to grab storyboard
 • GoToState – transition control to the target state
   (swallows errors with missing state)
 • Customizeable

consulting   training   design   debugging          wintellect.com
Visual State Manager
     foreach(VisualStateGroup group in
     VisualStateManager.GetVisualStateGroups(LayoutRoot))
     {
         if (!group.Name.Equals("RectangleStates")) continue;

             group.CurrentStateChanging += GroupCurrentStateChanging;
             group.CurrentStateChanged += GroupCurrentStateChanged;

             foreach(VisualState state in group.States)
             {
                 var state1 = state;
                 if (state.Storyboard != null)
                 {
                     state.Storyboard.Completed += (o, args) => _messages.Add(
                         string.Format("Storyboard for state {0} completed.",
                                         state1.Name));
                 }
             }
     }




consulting      training   design   debugging                           wintellect.com
Visual State Manager




consulting   training   design   debugging   wintellect.com
Visual State Aggregator
 • Part of Jounce framework (free to rip out and
   steal): http://jounce.codeplex.com/
 • Allows for coordination of visual states 100% from
   the UI (clean separation)
 • Create an “event” visual states participate in
   (define what state to transition to when the event
   is raised)
 • Raise an “event” with a trigger



consulting   training   design   debugging    wintellect.com
Visual State Aggregator
     <UserControl>
        <Grid x:Name="LayoutRoot">
        <i:Interaction.Behaviors>
           <vsm:VisualStateSubscriptionBehavior EventName="ActivatePanelB"
     StateName="Background" UseTransitions="True"/>
           <vsm:VisualStateSubscriptionBehavior
     EventName="DeactivatePanelB" StateName="Foreground"
     UseTransitions="True"/>
        </i:Interaction.Behaviors>
        </Grid>
     </UserControl>

     <Grid>
        <i:Interaction.Triggers>
           <i:EventTrigger EventName="MouseLeftButtonUp">
              <vsm:VisualStateTrigger EventName="ActivatePanelB"/>
           </i:EventTrigger>
        </i:Interaction.Triggers>
     </Grid>




consulting   training   design   debugging                           wintellect.com
Demo
   MVVM with Visual States




consulting   training   design   debugging   wintellect.com
Questions?




                            Jeremy Likness
                            Project Manager, Senior Consultant
                            jlikness@wintellect.com



consulting   training   design   debugging                       wintellect.com

Más contenido relacionado

Destacado

Success with informational texts.pptx
Success with informational texts.pptxSuccess with informational texts.pptx
Success with informational texts.pptxjsmalcolm
 
sentenza cassazione giovanni arcangioli - 17 febbraio 2009
 sentenza cassazione   giovanni arcangioli - 17 febbraio 2009 sentenza cassazione   giovanni arcangioli - 17 febbraio 2009
sentenza cassazione giovanni arcangioli - 17 febbraio 2009Voglioscendere
 
WORLD WATCH 2013 - check in now.
WORLD WATCH 2013 - check in now.WORLD WATCH 2013 - check in now.
WORLD WATCH 2013 - check in now.Christopher Peterka
 
Agile Comes To You
Agile Comes To YouAgile Comes To You
Agile Comes To YouCredera
 
Vibhuti patel book review anirban das social change vol. 45, no. 1
Vibhuti patel book review anirban das social change vol. 45, no. 1Vibhuti patel book review anirban das social change vol. 45, no. 1
Vibhuti patel book review anirban das social change vol. 45, no. 1VIBHUTI PATEL
 
Google+ Puts Facebook in Check and Facebook Moves its King
Google+ Puts Facebook in Check and Facebook Moves its KingGoogle+ Puts Facebook in Check and Facebook Moves its King
Google+ Puts Facebook in Check and Facebook Moves its KingJamie Nafziger
 
Censo da Indústria de Energia Limpa da Carolina do Norte
Censo da Indústria de Energia Limpa da Carolina do NorteCenso da Indústria de Energia Limpa da Carolina do Norte
Censo da Indústria de Energia Limpa da Carolina do NorteGiovanni Sandes
 
Obstacles to Health in South Los Angeles
Obstacles to Health in South Los AngelesObstacles to Health in South Los Angeles
Obstacles to Health in South Los Angelesreportingonhealth
 
Tablet and Slate Development with Silverlight
Tablet and Slate Development with SilverlightTablet and Slate Development with Silverlight
Tablet and Slate Development with SilverlightJeremy Likness
 
Managing Content to Enhance Client Value - MASAE Annual Conference
Managing Content to Enhance Client Value - MASAE Annual ConferenceManaging Content to Enhance Client Value - MASAE Annual Conference
Managing Content to Enhance Client Value - MASAE Annual ConferenceBecky Rasmussen
 
White is the new grey SEO Webinar
White is the new grey SEO WebinarWhite is the new grey SEO Webinar
White is the new grey SEO WebinarGaël Breton
 

Destacado (14)

Gee reception
Gee receptionGee reception
Gee reception
 
Success with informational texts.pptx
Success with informational texts.pptxSuccess with informational texts.pptx
Success with informational texts.pptx
 
sentenza cassazione giovanni arcangioli - 17 febbraio 2009
 sentenza cassazione   giovanni arcangioli - 17 febbraio 2009 sentenza cassazione   giovanni arcangioli - 17 febbraio 2009
sentenza cassazione giovanni arcangioli - 17 febbraio 2009
 
WORLD WATCH 2013 - check in now.
WORLD WATCH 2013 - check in now.WORLD WATCH 2013 - check in now.
WORLD WATCH 2013 - check in now.
 
8
88
8
 
Bi omap
Bi omapBi omap
Bi omap
 
Agile Comes To You
Agile Comes To YouAgile Comes To You
Agile Comes To You
 
Vibhuti patel book review anirban das social change vol. 45, no. 1
Vibhuti patel book review anirban das social change vol. 45, no. 1Vibhuti patel book review anirban das social change vol. 45, no. 1
Vibhuti patel book review anirban das social change vol. 45, no. 1
 
Google+ Puts Facebook in Check and Facebook Moves its King
Google+ Puts Facebook in Check and Facebook Moves its KingGoogle+ Puts Facebook in Check and Facebook Moves its King
Google+ Puts Facebook in Check and Facebook Moves its King
 
Censo da Indústria de Energia Limpa da Carolina do Norte
Censo da Indústria de Energia Limpa da Carolina do NorteCenso da Indústria de Energia Limpa da Carolina do Norte
Censo da Indústria de Energia Limpa da Carolina do Norte
 
Obstacles to Health in South Los Angeles
Obstacles to Health in South Los AngelesObstacles to Health in South Los Angeles
Obstacles to Health in South Los Angeles
 
Tablet and Slate Development with Silverlight
Tablet and Slate Development with SilverlightTablet and Slate Development with Silverlight
Tablet and Slate Development with Silverlight
 
Managing Content to Enhance Client Value - MASAE Annual Conference
Managing Content to Enhance Client Value - MASAE Annual ConferenceManaging Content to Enhance Client Value - MASAE Annual Conference
Managing Content to Enhance Client Value - MASAE Annual Conference
 
White is the new grey SEO Webinar
White is the new grey SEO WebinarWhite is the new grey SEO Webinar
White is the new grey SEO Webinar
 

Similar a Silverlight's Visual State Manager

Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAmir Barylko
 
JS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-NativeJS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-NativeJSFestUA
 
WPF for developers - optimizing your WPF application
WPF for developers - optimizing your WPF applicationWPF for developers - optimizing your WPF application
WPF for developers - optimizing your WPF applicationTamir Khason
 
Presentation wpf
Presentation wpfPresentation wpf
Presentation wpfdanishrafiq
 
D2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRollerD2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRollerWO Community
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationSean Burgess
 
Responsive WordPress workflow
Responsive WordPress workflowResponsive WordPress workflow
Responsive WordPress workflowJames Bundey
 
Xamarin 9/10 San Diego Meetup
Xamarin 9/10 San Diego MeetupXamarin 9/10 San Diego Meetup
Xamarin 9/10 San Diego MeetupSeamgen
 
Silverlight 2 For Developers
Silverlight 2 For DevelopersSilverlight 2 For Developers
Silverlight 2 For DevelopersMithun T. Dhar
 
Html5 Whats around the bend
Html5 Whats around the bendHtml5 Whats around the bend
Html5 Whats around the bendRaj Lal
 
"Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin...
"Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin..."Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin...
"Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin...Yandex
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletonGeorge Nguyen
 
CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)창석 한
 
Silverlight week2
Silverlight week2Silverlight week2
Silverlight week2iedotnetug
 

Similar a Silverlight's Visual State Manager (20)

Silverlight 5
Silverlight 5Silverlight 5
Silverlight 5
 
WOdka
WOdkaWOdka
WOdka
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescript
 
Html5 more than just html5 v final
Html5  more than just html5 v finalHtml5  more than just html5 v final
Html5 more than just html5 v final
 
Asp.Net Mvc Dev Days09
Asp.Net Mvc Dev Days09Asp.Net Mvc Dev Days09
Asp.Net Mvc Dev Days09
 
JS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-NativeJS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-Native
 
WPF for developers - optimizing your WPF application
WPF for developers - optimizing your WPF applicationWPF for developers - optimizing your WPF application
WPF for developers - optimizing your WPF application
 
Presentation wpf
Presentation wpfPresentation wpf
Presentation wpf
 
D2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRollerD2W Branding Using jQuery ThemeRoller
D2W Branding Using jQuery ThemeRoller
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
 
Responsive WordPress workflow
Responsive WordPress workflowResponsive WordPress workflow
Responsive WordPress workflow
 
Xamarin 9/10 San Diego Meetup
Xamarin 9/10 San Diego MeetupXamarin 9/10 San Diego Meetup
Xamarin 9/10 San Diego Meetup
 
Silverlight 2 For Developers
Silverlight 2 For DevelopersSilverlight 2 For Developers
Silverlight 2 For Developers
 
Html5 Whats around the bend
Html5 Whats around the bendHtml5 Whats around the bend
Html5 Whats around the bend
 
"Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin...
"Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin..."Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin...
"Responsive Web Design: Clever Tips and Techniques". Vitaly Friedman, Smashin...
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
 
DirectToWeb 2.0
DirectToWeb 2.0DirectToWeb 2.0
DirectToWeb 2.0
 
Franco arteseros resume
Franco arteseros resumeFranco arteseros resume
Franco arteseros resume
 
CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)
 
Silverlight week2
Silverlight week2Silverlight week2
Silverlight week2
 

Último

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 

Último (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 

Silverlight's Visual State Manager

  • 1. Silverlight’s Visual State Manager Jeremy Likness Project Manager, Senior Consultant jlikness@wintellect.com Copyright © 2011 consulting training design debugging wintellect.com
  • 2. what we do consulting training design debugging who we are Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins – we pull out all the stops to help our customers achieve their goals through advanced software-based consulting and training solutions. how we do it Training • On-site instructor-led training Consulting & Debugging • Virtual instructor-led training • Architecture, analysis, and design services • Devscovery conferences • Full lifecycle custom software development • Content creation Design • Project management • User Experience Design • Debugging & performance tuning • Visual & Content Design • Video & Animation Production consulting training design debugging wintellect.com
  • 3. Agenda • XAML • Dependency Properties • Coercion • Storyboards • “Lookless” Controls • Parts and States • Groups • States • Transitions • Demo: Visual State Explorer • Visual State Manager • Visual State Aggregator • Demo: MVVM with Visual States consulting training design debugging wintellect.com
  • 4. XAML • Extensible Application Markup Language • Declarative: – Initialize objects – Set properties of objects • Object graph • Behaviors • Triggers • Data-binding – clean separation of UI layer consulting training design debugging wintellect.com
  • 5. XAML Rectangle Type is Initialized <Rectangle Name="rectangle1" Width="100" Complex Dependency Property Value Height="100"> <Rectangle.Fill> <SolidColorBrush Color="Blue"/> </Rectangle.Fill> </Rectangle> Type Converter consulting training design debugging wintellect.com
  • 6. Dependency Properties • Actual value based on multiple inputs • Callback functionality • Required for animation • Backed by CLR properties • CLR wrapper (get/set) • Styles • Data-binding consulting training design debugging wintellect.com
  • 7. Dependency Properties public static readonly DependencyProperty IsSpinningProperty = Backing Store DependencyProperty.Register( "IsSpinning", typeof(Boolean), typeof(SilverlightExampleClass), null); CLR Property Façade public bool IsSpinning { get { return (bool)GetValue(IsSpinningProperty); } set { SetValue(IsSpinningProperty, value); } } consulting training design debugging wintellect.com
  • 8. Coercion • How do we compute the value of a dependency property? • Value Precedence… 1. Active animations (storyboard not stopped) 2. Local value (SetValue) 3. Template (ControlTemplate, DataTemplate) 4. Style 5. Default value consulting training design debugging wintellect.com
  • 9. Storyboards • Coerce property values • May transition over time • Can be cyclical • “Ending” not the same as “Stopping” • Key-frame vs. From/To/By • Color, Double, Point, Object consulting training design debugging wintellect.com
  • 10. Storyboards <StackPanel x:Name="LayoutRoot" Background="White"> Range <StackPanel.Resources> <Storyboard x:Name="myStoryboard"> <DoubleAnimation From="30" To="200" Duration="00:00:3" Storyboard.TargetName="myRectangle" Storyboard.TargetProperty="Height"> Target <DoubleAnimation.EasingFunction> <BounceEase Bounces="2" EasingMode="EaseOut" Bounciness="2" /> </DoubleAnimation.EasingFunction> Easing </DoubleAnimation> </Storyboard> </StackPanel.Resources> <Rectangle x:Name="myRectangle" MouseLeftButtonDown="Mouse_Clicked" Fill="Blue" Width="200" Height="30" /> </StackPanel> consulting training design debugging wintellect.com
  • 11. “Lookless” Controls • Custom controls separate logic from visual appearance • Allows modifying visual appearance without changing underlying code • Styles • Templates • “Control Contract” – parts and states consulting training design debugging wintellect.com
  • 12. Parts and States • Parts – named sections within the control • States – change appearance based on context consulting training design debugging wintellect.com
  • 13. Groups • Set of mutually exclusive states for a control • Orthogonal • Controls may have multiple states, but only one state per group • Example: CheckBox – CommonStates (Normal, MouseOver, Pressed, etc.) – CheckStates (Checked, Unchecked, InDeterminate) – FocusStates – ValidationStates consulting training design debugging wintellect.com
  • 14. States • Appearance of control in a particular state • “Base” state means “no state” • Typically you will add a default state and set the control to that state, i.e. “Normal” • States are created by a storyboard • The storyboard plays and may have animation but is not stopped until the state within that group changes consulting training design debugging wintellect.com
  • 15. States <ControlTemplate TargetType="Button"> <Grid > Root Visual <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> Group <VisualState x:Name="Normal" /> <VisualState x:Name="MouseOver"> Default State <Storyboard> <ColorAnimation Storyboard.TargetName="ButtonBrush“ Storyboard.TargetProperty="Color" To="Red" /> </Storyboard> </VisualState> Storyboard & Animation </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid.Background> <SolidColorBrush x:Name="ButtonBrush" Color="Green"/> </Grid.Background> </Grid> </ControlTemplate> consulting training design debugging wintellect.com
  • 16. Transitions • Control transition between one state to another • Generated duration will automatically transition between old storyboard and new storyboard • Control isn’t in the “new” state until the transition completes • New storyboard gives more control (this is stopped once the transition completes) • Stop old storyboard > start transition storyboard > stop transition storyboard > start new storyboard consulting training design debugging wintellect.com
  • 17. Transitions Uses State Storyboard <VisualStateGroup.Transitions> <VisualTransition To="GreenState" GeneratedDuration="0:0:1“/> <VisualTransition From="GreenState" To="ShowState"> <Storyboard Duration="0:0:1"> <DoubleAnimation Uses Transition Storybard Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.R otationY)" From="-80" To="-0"/> <DoubleAnimation Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTra nsform.X)" From="-205" To="0"/> </Storyboard> </VisualTransition> </VisualStateGroup.Transitions> consulting training design debugging wintellect.com
  • 18. Demo Visual State Explorer consulting training design debugging wintellect.com
  • 19. Visual State Manager • Manages all logic and transitions • GetVisualStateGroups – iterate all groups in the control – Iterate states and transitions within the group – CurrentState, CurrentStateChanging, CurrentStateChang ed – Use state/transition to grab storyboard • GoToState – transition control to the target state (swallows errors with missing state) • Customizeable consulting training design debugging wintellect.com
  • 20. Visual State Manager foreach(VisualStateGroup group in VisualStateManager.GetVisualStateGroups(LayoutRoot)) { if (!group.Name.Equals("RectangleStates")) continue; group.CurrentStateChanging += GroupCurrentStateChanging; group.CurrentStateChanged += GroupCurrentStateChanged; foreach(VisualState state in group.States) { var state1 = state; if (state.Storyboard != null) { state.Storyboard.Completed += (o, args) => _messages.Add( string.Format("Storyboard for state {0} completed.", state1.Name)); } } } consulting training design debugging wintellect.com
  • 21. Visual State Manager consulting training design debugging wintellect.com
  • 22. Visual State Aggregator • Part of Jounce framework (free to rip out and steal): http://jounce.codeplex.com/ • Allows for coordination of visual states 100% from the UI (clean separation) • Create an “event” visual states participate in (define what state to transition to when the event is raised) • Raise an “event” with a trigger consulting training design debugging wintellect.com
  • 23. Visual State Aggregator <UserControl> <Grid x:Name="LayoutRoot"> <i:Interaction.Behaviors> <vsm:VisualStateSubscriptionBehavior EventName="ActivatePanelB" StateName="Background" UseTransitions="True"/> <vsm:VisualStateSubscriptionBehavior EventName="DeactivatePanelB" StateName="Foreground" UseTransitions="True"/> </i:Interaction.Behaviors> </Grid> </UserControl> <Grid> <i:Interaction.Triggers> <i:EventTrigger EventName="MouseLeftButtonUp"> <vsm:VisualStateTrigger EventName="ActivatePanelB"/> </i:EventTrigger> </i:Interaction.Triggers> </Grid> consulting training design debugging wintellect.com
  • 24. Demo MVVM with Visual States consulting training design debugging wintellect.com
  • 25. Questions? Jeremy Likness Project Manager, Senior Consultant jlikness@wintellect.com consulting training design debugging wintellect.com