29
Creating Rich, Dynamic User Interfaces with Silverlight 2 Controls Karen Corby Program Manager Microsoft Corporation http://scorbs.com/work

Creating Rich, Dynamic User Interfaces with Silverlight 2

Embed Size (px)

DESCRIPTION

See how to use the Microsoft Silverlight 2 control model to efficiently design and develop custom controls, style existing controls, create control templates, and package your controls for re-use to develop Rich Internet Applications. Also hear about the capabilities for localization and accessibility.

Citation preview

Page 1: Creating Rich, Dynamic User Interfaces with Silverlight 2

Creating Rich, Dynamic

User Interfaces with Silverlight 2 ControlsKaren CorbyProgram ManagerMicrosoft Corporationhttp://scorbs.com/work

Page 2: Creating Rich, Dynamic User Interfaces with Silverlight 2

Control Model

Silverlight 1

Silverlight 2

UserControl

Custom Control

Styling

Skinning

Parts Model

Page 3: Creating Rich, Dynamic User Interfaces with Silverlight 2

Motivation for UserControl

Page 4: Creating Rich, Dynamic User Interfaces with Silverlight 2

Motivation for UserControl

Page 5: Creating Rich, Dynamic User Interfaces with Silverlight 2

UserControl

ScenarioFixed look with some logicSplit large page into smaller chunksReuse xaml/logic in multiple places

Platform Support<UserControl x:Class=“MyControl”> … </>public partial class MyControl : UserControl {}XAML is optional

Page 6: Creating Rich, Dynamic User Interfaces with Silverlight 2

UserControl Trivia

Update from 1.1 AlphaReplaces Control.InitializeFromXaml(“…”)

A Silverlight “page” is a UserControlVisual elementsDatabindingTabbingMouse & keyboard events… and so on

Page 7: Creating Rich, Dynamic User Interfaces with Silverlight 2

UserControl

Building a UserControl

demo

Page 8: Creating Rich, Dynamic User Interfaces with Silverlight 2

Accessibility

Complete keyboard accessibilityFull tab navigation supportFull focus supportCan implement own directional navigation

Screen reader support coming in Beta2Based on UIAutomationMark Rideout’s video:

Some additional work for full 508 compliance

High Contrast

Page 9: Creating Rich, Dynamic User Interfaces with Silverlight 2

User Controls

Control Logic Control Visuals

Custom Controls

Page 10: Creating Rich, Dynamic User Interfaces with Silverlight 2

Skinning

Property Bag “Styling”

Scenario Tweek minor visual characteristics

Platform SupportManually setting visual properties on control<Style>

Customizing Existing Controls

Styling

Page 11: Creating Rich, Dynamic User Interfaces with Silverlight 2

Styling

Using <Style>

demo

Page 12: Creating Rich, Dynamic User Interfaces with Silverlight 2

Property Bag “Styling”

ResourcesA shared XAML asset that can be referenced by multiple elements in your application.

<Style>A set of properties that can be applied to controls, text, shapes, …

Silverlight 2“Write once” behaviorApplication theme styles not supportedBasedOn styles not supported

Page 13: Creating Rich, Dynamic User Interfaces with Silverlight 2

Customizing Existing Controls

Skinning

“Skinning”

ScenarioCompletely replace control’s visuals

Platform Support<ControlTemplate>Styling

Page 14: Creating Rich, Dynamic User Interfaces with Silverlight 2

Skinning

Using <ControlTemplate>

demo

Page 15: Creating Rich, Dynamic User Interfaces with Silverlight 2

Skinning

<ControlTemplate>A set of elements that make up the visual structure of a control.

{TemplateBinding}A link between the template visuals and the control’s visual properties

Page 16: Creating Rich, Dynamic User Interfaces with Silverlight 2

Building a new Custom Control

Control Logic Control Visuals

Page 17: Creating Rich, Dynamic User Interfaces with Silverlight 2

Building a Custom Control

ScenarioPiece of custom logicDesigners can customize look

Platform SupportDerive from Control classSupply built-in style

Page 18: Creating Rich, Dynamic User Interfaces with Silverlight 2

Custom Control

Building an ImageControl

demo

Page 19: Creating Rich, Dynamic User Interfaces with Silverlight 2

Custom Control Structure

Control subclass

generic.xamlAssembly resource in controls dllDefines “built in” styles for control

Page 20: Creating Rich, Dynamic User Interfaces with Silverlight 2

I’ve got your RootElement,

Pressed State, etc..

I wonder what I

need to put in my template

Defining the Control Contract

Control Logic Control Visuals

I need a RootElement,

Pressed State, etc..

Page 21: Creating Rich, Dynamic User Interfaces with Silverlight 2

Introducing the Parts ModelGoals

How to structure your controlDefined separation between logic & visualsExplicit control contract

Recommended patternNot enforced by runtimeWill be supported by Blend

Page 22: Creating Rich, Dynamic User Interfaces with Silverlight 2

Parts Model

Element PartsNamed element in templateType: FrameworkElement, Panel, Button, etc..Control logic will control element in some way

DownButton UpButton

Thumb

Track

Page 23: Creating Rich, Dynamic User Interfaces with Silverlight 2

Part Model

States PartsKeyed resource inside template’s root elementType: StoryboardControl logic begins & stops storyboard

MouseOver

Transition

Initiator

Pressed

STATE part

Code starts/stopsanimation.

Page 24: Creating Rich, Dynamic User Interfaces with Silverlight 2

ImageControl Parts

RootElementFocusVisualElement

NormalStateMouseOverStatePressedState

Page 25: Creating Rich, Dynamic User Interfaces with Silverlight 2

Parts Model

ImageControl Parts Contract

demo

Page 26: Creating Rich, Dynamic User Interfaces with Silverlight 2

Developers & Designers

Page 27: Creating Rich, Dynamic User Interfaces with Silverlight 2

What's in YourControl Model Toolbox?

UserControls Custom Controls

Styles & TemplatesParts Model

Page 28: Creating Rich, Dynamic User Interfaces with Silverlight 2

© 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.

Page 29: Creating Rich, Dynamic User Interfaces with Silverlight 2