280 likes | 390 Views
Andy Beaulieu MCT, MCSD.NET WPF & Silverlight Insiders Microsoft MVP Client App Dev www.spritehand.com www.andybeaulieu.com. Silverlight 2 D e sign & animation techniques. Agenda. Using Expression Blend Storyboard Animations Styling Visual State Manager ImplicitStyleManager
E N D
Andy Beaulieu MCT, MCSD.NET WPF & Silverlight Insiders Microsoft MVP Client App Dev www.spritehand.com www.andybeaulieu.com Silverlight 2 Design & animation techniques
Agenda • Using Expression Blend • Storyboard Animations • Styling • Visual State Manager • ImplicitStyleManager • Custom Animations • Adding Physics • Silverlight Live Streaming
Storyboard Animations • Simplest way to animate • Good for “Static” Animations • Can animate many Properties: • Opacity • Position • Scale • Rotation • Etc…… • Very Small Footprint • XAML is small for Vector Images • Key Frame based, so minimal markup
Storyboard Animations, cont’d • Use Expression Blend to Design • Encapsulate Animations in separate UserControls! • Easier Maintenance • Smaller Pieces, Better Abstraction • Package animation with artwork
Styling Styles can be defined at the Container level (Grid, Canvas, etc.): … OR at the Application Level, inside app.xaml: … and are then applied to controls using the Style tag:
Styling, cont’d • Control Templates • Are special Style information used to specify what elements make up a control • EX: A Button may be made up of a Border, Grid, and Rectangle
Styling, cont’d • You can use Expression Blend to Create Styles + Control Template! • Right-Click Object • Select Edit Control Parts (Template) • Select Edit a Copy to break down control into pieces of existing style • Select Create Empty to “Start from Scratch” with no pre-existing Style info
Visual State Manager (VSM) • Allows animation behavior defined at the Style level • Allows re-use of behavior across controls of the same type • Defined at various levels: • App.xaml for Application-Wide use • UserControl.Resources for Page-Level use • Control.Resources for Control-Level use
Visual State Manager (VSM), cont’d • Two types of State Animation: • State Transition Animation • MouseOver, Pressed, Disabled, etc. • In-State Animation • While Mouse is Over, While Mouse is Pressed, etc. • To make an in-state animation, just set the storyboard to AutoReverse, Repeat Forever.
Implicit Styles • Wouldn’t it be NICE if we could (for example) make all TextBlock’s look the same in one easy step? • Unfortunately, Silverlight 2 DOES NOT support Implicit Styles (but WPF does)
ImplicitStyleManager • Fix for Missing Implicit Styles in Silverlight 2 • Part of Silverlight Toolkit • http://www.codeplex.com/Silverlight • Will apply a Theme to a given container (Grid, Canvas, UserControl, etc.) and all of its Children. • Toolkit also comes with lots of sample Themes • Useful for structuring your own Themes
ImplicitStyleManager • Steps to Use • Add a ResourceDictionaryxaml file to the project • Ex: \SilverlightToolkit\Source\Controls.Theming.BureauBlue\Theme.xaml • If using sample themes like above, rename the file to Microsoft.Windows.Controls.Theming.ThemeName.xaml • Set the Build Action to Resource • In the Loaded Event, set the style:using Microsoft.Windows.Controls.Theming;Uri uri = new Uri(@“DefaultNamespace;component/Microsoft.Windows.Controls.Theming.ThemeName.xaml", UriKind.Relative);ImplicitStyleManager.SetResourceDictionaryUri(LayoutRoot, uri);ImplicitStyleManager.SetApplyMode(LayoutRoot, ImplicitStylesApplyMode.Auto);ImplicitStyleManager.Apply(LayoutRoot); • Be sure to replace DefaultNamespace and ThemeName • Designers can open ResourceDictionary in Blend and Edit
Custom Animations • Good for “Dynamic Animations” • Examples: • Animation based on User Input • Game AI • Physics
Custom Animations, cont’d • Use CompositionTarget.Rendering Event • Each Rendering Event is a frame of animation • Example:
Physics • Applies real-world feel to UI • Use to make UI feel “Natural” • Think “Minority Report” • Examples: • DeepZoom • Games
Some Typical Physics Terms • Body: The object in a simulation, containing mass, intertia, etc. • Geometry: The shape of the object in the simulation, used for collision detection • Joint: An object that joins two Bodies together • Angular Spring: An object that forces a joint to a particular rotation
Physics, cont’d • “Physics is Hard!!!” • Use a Physics Engine • Farseer: www.codeplex.com/farseerphysics • Even with pre-built engine, still complex: • How to correlate Silverlight XAML elements with Physics elements? • What settings for gravity, joints, springs, etc?
“Physics Helper” • Makes Physics much Easier! • Use Expression Blend 2.5 to Draw out Physics Simulation • User Controls for Joint, Static Body, Simulation, etc.
Silverlight Live Streaming • “Free” Hosting for your SL Apps! • Also Video • 10 GB Free • Silverlight.live.com
Andy Beaulieu MCT, MCSD.NET, Silverlight Insiders www.spritehand.com www.andybeaulieu.com SUMMARYQ & A