Mike Ormond's Blog

Musings on mobile development and Windows Phone 7 in particular.

Mix08 Session - Silverlight Controls

Mix08 Session - Silverlight Controls

  • Comments 2

Again, really a set of shorthand notes but hopefully a few nuggets in here that you might find useful...

User Controls

  • Fixed look with some logic
  • Split large pages into smaller chunks
  • Re-use
  • Root XAML element is UserControl and partial class derives from UserControl
  • Replaces 1.1's Control.InitializeFromXaml()
  • Can do anything in UserControl you can do in Page

NB handling of KeyDown even now supported at the element level (rather than application level)

Accessibility

  • Full keyboard accessibility
    • Full tab nav support
    • Full focus suport
    • Can implement own directioanal nav
  • Screen Reader support coming in Beta 2
    • Based on UIAutomation
    • Video will be available soon on Mix site
  • Some additional work in progress for Section 508 compliance

Custom Controls

Define behviour but allow UI to change - styling and skinning

  • Styling
    • Tweak minor visuals by setting properties
    • Or use Style property bag
      • Define as a resource (eg in Application.Resources)
      • Style element contains Setter elements that define property/value pairs
      • x:Key defines a reference for the style
      • Usage syntax eg <TextBox Style='{StaticResource StyleKey}' Text='... />
    • Differences to WPF
      • Write once - cannot clear styles or swap styles at runtme
      • Application level styles not supported (eg all buttons)
      • BasedOn styles not supported
  • Skinning
    • Allows you to completely replace control visuals
    • Uses ControlTemplate to define control visuals
    • Can use TemplateBindings to bind control properties to user defined usage properties

Custom controls come in useful where you want custom logic but allow designers to override visuals

  • Custom Control definition
    • Derive from Control
    • No default visuals - need to specify this in generic.xaml compiled into assembly as resource
      • Contains a ResourceDictionary
      • Defines Styles including the Template / ControlTemplate that specifies the visuals
  • Parts Model
    • Goals
      • How to structure your control
      • Defined separation between control logic and visuals
      • Explicit control contract
      • Recommended pattern - not enforced by runtime
      • Will be supported by Blend
    • What is it?
      • Element Parts
        • Named element in template
        • Type: FrameworkElement, Panel, Button etc
        • Control element will control element in some way
      • State Parts
        • Keyed resource inside template's root element
        • Type:Storyboard
        • Control logic begins and stops storyboard
      • Allows you to call out explicitly which parts the control template is expecting so the behaviours can be maintained when the template is modified
Technorati Tags: ,
Page 1 of 1 (2 items)