37

Building Microsoft Silverlight Controls

Embed Size (px)

DESCRIPTION

Building Microsoft Silverlight Controls. Karen Corby Lead Program Manager Silverlight 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 ...” - PowerPoint PPT Presentation

Citation preview

Page 1: Building Microsoft  Silverlight  Controls
Page 2: Building Microsoft  Silverlight  Controls

Building Microsoft Silverlight Controls

Karen CorbyLead Program ManagerSilverlighthttp://scorbs.com/work

Page 3: Building Microsoft  Silverlight  Controls
Page 4: Building Microsoft  Silverlight  Controls

“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

Page 5: Building Microsoft  Silverlight  Controls

On The Menu

StylingSkinningData BindingLayout

Page 6: Building Microsoft  Silverlight  Controls

Customizing Control Visuals

SkinningStyling

Styling

“Property Bag” Styling

<Style> element

Works with Controls, UserControls, Shapes, Panels

Page 7: Building Microsoft  Silverlight  Controls

Styling

demo

Page 8: Building Microsoft  Silverlight  Controls

Styling

demo

Page 9: Building Microsoft  Silverlight  Controls

New Styling Features

BasedOn StylesExtend existing styles

Merged Resource DictionariesBreakout RDs into different files

Page 10: Building Microsoft  Silverlight  Controls

Customizing Control VisualsSkinning

SkinningStyling

Completely replace visuals

<ControlTemplate> element

{TemplateBinding} extension

Works with Custom Controls (not UserControls, Panels,

Shapes)

Page 11: Building Microsoft  Silverlight  Controls

Defining the Control ContractI need a

Thumb, Pressed state

etc..

I wonder what I need to put in my template…

I’ve got your Thumb,Pressed

state, etc..

Control Logic Control Visuals

Control.cs <ControlTemplate>

Custom Controls

Page 12: Building Microsoft  Silverlight  Controls

Parts And States Model

GoalsMake it easy to skin your controlDefined separation between logic & visualsExplicit control contract

Recommended patternNot enforced by runtimeSupported by Blend

Page 13: Building Microsoft  Silverlight  Controls

Parts

Named element (x:Name) in templateCode manipulates element in some way Not all Control Contracts have Parts

DownRepeatButton

UpRepeatButton

Thumb

Track

Page 14: Building Microsoft  Silverlight  Controls

States

Visual look of control in a particular state<VisualState> elementNot all Control Contracts have States

MouseOver Pressed

Page 15: Building Microsoft  Silverlight  Controls

Transitions

Visual look as control goes between states<VisualTransition> element

MouseOverPressed

VisualTransition

Page 16: Building Microsoft  Silverlight  Controls

State Group

Set of mutually exclusive statesDifferent state groups are orthogonal<VisualStateGroup> element

MouseOver

Normal

ReadOnly

Disabled

Unfocused

Focused

Valid

InvalidUnfocused

ValidUnfocused

CommonStates

FocusStates

ValidationStates

Page 17: Building Microsoft  Silverlight  Controls

Skinning

Replacing TextBox’s ControlTemplate

demo

Page 18: Building Microsoft  Silverlight  Controls

Using States & Transitions

VisualStateManager.VisualStateGroupsAttached property on root visual of ControlTemplate

VisualStateGroupContains group of related states

VisualState classContains storyboard that represents visual look

VisualTransition classContains duration for automatic transition animationsContains storyboard for explicit transition animationDefault, or “To/From” transiitionsGeneratedEasingFunction coming SL3 Post-Beta

Page 19: Building Microsoft  Silverlight  Controls

Validation

DataObject

Setter

<VisualState/>in

ControlTemplate

TextBox.Text={Binding}

New Value

New Value

Validation.Errors

BindingEngine

ExceptionValidation State Transition

Page 20: Building Microsoft  Silverlight  Controls

Validation & Bindings

NotifyOnValidationErrorsValidatesOnExceptions

Binding flags. Initiate validations.

UpdateSourceTriggerNew Binding flag. Enable explicit update.

BindingExpression.UpdateSource()

Manually update associated Binding.

Page 21: Building Microsoft  Silverlight  Controls

Bindings

RelativeSource BindingSelf & TemplatedParent as sourcePower of full binding in Templates

Attached DP sources, converters, two-way, etc

DependencyProperty as SourcesUpdate based on DP changes. 

Page 22: Building Microsoft  Silverlight  Controls

Validation UI "Out of Box"

TextBoxCheckBoxRadioButtonComboBoxListBoxPasswordBox (post-Beta)

Page 23: Building Microsoft  Silverlight  Controls

Skinning in Blend

TextBox

demo

Page 24: Building Microsoft  Silverlight  Controls

Binding & Styles

ElementName Binding“UI to UI Binding”FrameworkElement can be binding Source

Change Style at runtimeRemove “write once” Style limitation

Page 25: Building Microsoft  Silverlight  Controls

Silverlight Styling vs WPF Styling

Implicit StylesSee Toolkit talk

Dynamic Resources

TriggersBlend’s Behaviors

Page 26: Building Microsoft  Silverlight  Controls

Creating Custom Controls

Control Logic Control Visuals

Control.cs <ControlTemplate>

Page 27: Building Microsoft  Silverlight  Controls

RatingControl

Page 28: Building Microsoft  Silverlight  Controls

StarControlRatingControl

demo

Page 29: Building Microsoft  Silverlight  Controls

Building a New Custom Control

Control subclass“Look-less” by default

generic.xamlResourceDictionary with Built-in Style

DefaultStyleKeyUsed to determine which built-in style to use

Page 30: Building Microsoft  Silverlight  Controls

Creating The Control Class Logic

[TemplatePart] & [TemplateVisualState]

NOT used by runtime. Leveraged by tools.

public static VisualStateManager.GoToState()

Manages visual state change logic & transitions

Page 31: Building Microsoft  Silverlight  Controls

Silverlight & WPF Skinning

Same Model

VisualStateManager in WPF Toolkit

See WPF/SL Talk

Page 32: Building Microsoft  Silverlight  Controls

Layout

Custom Panels

Two pass algorithmsMeasureArrange

Page 33: Building Microsoft  Silverlight  Controls

Layout: Measure

Layout:How much space do you think you need?

Panel:Let me ask my children…

Brb

Panel:OK, I asked each of them.OMG - I need 1000 x 800

Layout:Gotcha. 1000 x 800. ttys

Page 34: Building Microsoft  Silverlight  Controls

Layout: Arrange

Layout:OK – Got the space for ya.Arrange yourself in here.

Panel:Will do. Let me go arrange all my children.

One sec.

Panel:OK, I gave them each some space at a specific

X,Y. BTW, here’s the space I actually ended up using.

Layout:Sweet. See you at the tables later? LOL!

Page 35: Building Microsoft  Silverlight  Controls

Putting it Together

Using Our Controls with Layout

demo

Page 36: Building Microsoft  Silverlight  Controls

Power of the Siverlight Control Model

StylingSkinningDataBindingLayout

A true branded experience permeates every aspect of you site.

Page 37: Building Microsoft  Silverlight  Controls

Resources

My blog (will post video & source)http://scorbs.com/work

Wishpot APIs:http://www.wishpot.com/help/developers.aspx

Silverlighthttp://silverlight.net