370 likes | 531 Vues
Silverlight 2 Control Model. Karen Corby Senior Program Manager http://scorbs.com/work. “One major difference between a site with a strong Brand Image ... and one with weak Brand Image ... is that brand positioning permeates every part of a strong site ...” - Forrester, June 9, 2005.
E N D
Silverlight 2 Control Model Karen Corby Senior Program Manager http://scorbs.com/work
“One major difference between a site with a strong Brand Image ... and one with weak Brand Image ... is that brand positioning permeates every part of a strong site ...” • - Forrester, June 9, 2005
On The Menu • Overview of Control Model • Skinnable Control and Parts & States Model • Silverlight & WPF
Silverlight 2 Control Model • UserControl • Custom Control • Styling • Skinning
User Controls Custom Controls Modularized Logic Designer Can Update Look Application Decomposition “Cheesy Re-use” Control Logic Control Visuals
Property Bag Styling Customizing Existing Controls <Grid> <Grid.Resources> <Style x:Key="ButtonStyle" TargetType="Button"> <Setter Property="Foreground" Value="Gray"/> <Setter Property="Background" Value="Purple"/> <Setter Property="FontStyle" Value="Italic"/> <Setter Property="FontFamily" Value="Cool.tff#Cool"/> </Style> </Grid.Resources> <Button Style="{StaticResourceButtonStyle}" Content="Button" /> </Grid> Styling Skinning
Skinning Customizing Existing Controls <Grid> <Grid.Resources> <!-- Button Template --> <ControlTemplate x:Key="ButtonTemplate" TargetType="Button"> <Grid> <Path Height="120.646" Width="129.736" Stretch="Fill" Data="M204, ... , 155" Stroke="#FFF77474“ Fill="{TemplateBinding Background}"/> <ContentPresenter Foreground="White" ... /> </Grid> </ControlTemplate> </Grid.Resources> <!-- Button --> <Button Content="Button" Template="{StaticResourceButtonTemplate}"> <Button.Background> <RadialGradientBrush> <GradientStop Color="#FFF4A1A1"/> <GradientStop Color="#FFBD2121" Offset="1"/> </RadialGradientBrush> </Button.Background> </Button> </Grid> Styling Skinning
Silverlight 2 Control Model • UserControl • Custom Control • Styling • Skinning • How do you create a new Custom Control?
demo Building a Custom Control
Custom Control Structure • Control subclass • “Look-less” by default • generic.xaml • ResourceDictionary with Built-in Style • DefaultStyleKey • Used to determine which built-in style to use
Defining the Control Contract I wonder what I need to put in my template… I need a Thumb, Pressed state etc.. I’ve got your Thumb, Pressed state, etc.. Control Logic Control Visuals
Introducing The Parts And States Model • Goals • How to structure your control • Defined separation between logic & visuals • Explicit control contract • Recommended pattern • Not enforced by runtime • Will be supported by Blend
Parts • Named element in template • Code manipulates element in some way • Not all Control Contracts have Parts DownRepeatButton Thumb UpRepeatButton Track
States • Visual look of control in a particular state MouseOver Pressed
Transitions • Visual look of control as it goes between states VisualTransition MouseOver Pressed
State Group • Set of mutually exclusive states • Different state groups are orthogonal
demo CheckBox Skin
Using States • VisualStateManager.VisualStateGroup • VisualStateGroup class • VisualState class • Contains storyboard that represents visual look
Using Transitions • VisualTransition class • Contains duration for automatic transition animations • Automatic Transition Animations • Generate linear transitions for properties set in VisualState by Color, Point, & Double animations
Selecting The VisualTransition • Types of transitions: (MouseOver -> Pressed) • From/To • <VisualTransition To=“Pressed” From=MouseOver” …> • To • <VisualTransition To=“Pressed” … > • From • <VisualTransition From=“MouseOver” … > • Default • <VisualTransition …> • Selects most specific transition
VisualStateManager VisualStateManager GoToState() VisualStateGroups Defined in template Called in control code
demo WeatherControl
Microsoft Confidential Creating The Control Class Logic • [TemplatePart] & [TemplateVisualState] • NOT used by runtime. Leveraged by tools. • public static VisualStateManager.GoToState() • Manages visual state change logic & transitions • public override void OnApplyTemplate() • Called when new template has been applied
More Interesting Transitions… • Can provide explicit transitions animations • VisualTransition.Storyboard
demo Skinning in Blend
Silverlight & WPF Control Model • The Same: • UserControl, CustomControl • <Style>, <ControlTemplate> • Silverlight 2’s <Style> • Write-Once Style Property • No BasedOn Styles Support • No Application-level Themes Support • VisualStateManager on WPF? • Triggers in Silverlight?
VisualStateManager in WPF • Enables easy port of controls & skins • Today: • http://www.codeplex.com/wpf/Release • Future: • Next release of WPF
demo VisualStateManager on WPF
VisualStateBehaviors • Attach VSM skin to existing WPF control • WPFToolkit comes with: • ButtonBaseBehavior { Button, ToggleButton} • ListBoxItemBehavior • ProgressBarBehavior • TextBoxBehavior • ToggleButtonBehavior {CheckBox, RadioButton}
Triggers in Silverlight • XAML can react to property changes or events • Expected in a future release of Silverlight • VisualStateManager to work with Triggers • <Trigger …> • <GoToState “MouseOver”/> • </Trigger>
Be Your Own Button • Use Custom Controls, ControlTemplates & Visual StateManager to create deeply customized, branded controls • Control Model consistency between WPF & Silverlight http://scorbs.com/work
evaluations Please fill out the online evalutions!
Q&A Please use the microphones provided
Links • Karen Corby’s Blog: • http://scorbs.com/work • Silverlight Site • http://silverlight.net • Silverlight Toolkit • http://codeplex.com/Silverlight • WPF Toolkit • http://www.codeplex.com/wpf
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.