Compsoft Flexible Specialists

Compsoft plc

Compsoft Weblog Compsoft Website News Archive Privacy Policy Contact Us  

Monday, November 08, 2010

Øredev 2010 - Day 1 - Tristan Smith

Silverlight Bootcamp
Originally due to be given by Shawn Wildermuth (Silverlight MVP) and then by Tim Heuer (Silverlight Program Manager), it ended up being given by Einar Ingebrigtsen Norwegian Silverlight MVP and developer of the Baldur 3D Silverlight engine. He gave a decent comprehensive overview and exploration of Silverlight.
The talk itself was interspersed with loud exclamations from the REST talk next door 'BOOM, BOOM, BOOM HEADSHOT!' and 'What the **** is this application' were heard by the clearly passionate Thoughtworks guys next door.
Starting with a comprehensive overview of what Silverlight is, Einar talked us through the breakdown of the plugin, how the CLR, DLR and rendering engine fit into it.
He covered topics such as Dependency Properties, RoutedEvents, Storyboards, ContentControls, Animations, DataBinding and a lot more. The aim of the talk was to get a 99% coverage of Silverlight so I'll just cover some details, I thought might be of interest, in this post.
RoutedEvents follow a similar path to html DOM events except for some key differences
- Bubbling only goes up the tree (focus, lostfocus)
- EventArgs Handled property can be set to true to handle the event (this doesn't exist for all events)
Storyboards
- Anything can be animated (made to change over time, not just visual properties)

ContentControl
- Custom controls you can attribute up which property to use as the Content property
He gave us a Xaml centric walk around Blend covering:
Animations
- Animate colors, values, over time, with easing etc.
Triggers
- EventTrigger is the only option, which has a single RoutedEvent (Loaded) with a single action, BeginStoryboard
Sample data
- Lets you create sample data that's easily bound in Blend, makes it easier to design when you can visualise the final result.
- Basic types only
- Creates sample data schema, xaml etc in the project and an associated resource file with the items in it
Dependency Properties
Used to add bindable properties.
Resources
All UIElements can have an associated resource, these resources apply to the whole hierarchy of that UIElement.
Resources are stored as dictionaries so they have a key to get access to them and can store anything (a Class instance for example).
MergedResourceDictionary allows you to pull in dictionaries from elsewhere
Styles
Styling doesn't mean just visual styles, you specify TargetType but can change any property at all.
Styles are inheritable making base styles with overridable style parts possible.
VisualStateManager
Controls can have states and transition between them, Focused, MouseOver etc.
Validation
Binding has Validation hooks - ValidatesOnException, ValidatesOnNotifyDataErrors if the object being bound implements IDataErrorInfo + INotifyDataErrorInfo
Control value default
On controls you can set properties of TargetNullValue='None' and FallbackValue='Data Context not set' so that you can have default values for when nothing is specified and when data has not been bound.
TypeConverters
Exposed properties on your object model can declare the TypeConverter to use (To allow scenarios such as converting a selected product code into a product instance).
You point to a TypeConverter by attaching an attribute
Templates
Blend makes it easy to edit templates based on existing controls, this is often a handy starting point. In order to get your bound property content to appear, you need to ensure you add a ContentPresenter control
Timers
You get access to two, DispatchTimer and the CompositionTarget Rendering event (which is fired as many times as you have MaxFramesPerSecond configured).
The DispatchTimer runs on its own thread.
To work against the UI, you need to go via the Dispatcher
LocalConnection API
- Used to communicate between SL instances on a page��
Fonts
Silverlight uses its own font engine, you get 9 fonts by default but you can embed your own fonts.
WriteableBitmap
Introduced in Silverlight 3, it's surprising fast, Einar's 3D engine project makes a lot of use of it.
Localization
Tooling is a bit rubbish at the moment, you have to manually change the access modifier in the Resource file but then because the tooling doesn't modify the constructor to be public, you have to derive the resource class to add a public constructor.
Serialization
- DataContractSerializer and JsonSerializer only
- References are maintained (circular references sorted for you)
- IgnoreDataMember to skip serialization of properties
Printing
Is still lame, no paging support, pixel not DPI based. If your image is bigger than the available print area, it won't intelligently continue, it'll lose the excess.
- The cool feature, is that you can pass specific UIElements to be printed.
WCF
- Add service reference handy proxy generation
- Validation for databinding is a pain because you lose IDataErrorInfo in transit.
MVVM
ViewModel contains State and Behaviour
Built in Commands mechanism - requires a new class for each one.
MVVM Light give you some time saving Behavioural additions.
You create your commands as methods on your ViewModel and call delegates passing your method.
Event aggregation - a contract (message type) that view models can subscribe to / publish. MVVM Light has this called Messager.
Einar showed us a convention he uses where he creates a directory per feature, in this case it was a Customer folder with a View, ViewModel and CustomerDataSource.
The ViewModel encapsulates the state and behaviour. It uses a generic DelegateCommand to wire up to a local method (Load for example) rather than implement the full ICommand.
MVVM Light has an implementation of the delegate calling code.
Jeff Wilcox pointed us at the SilverlightToolkit
Is a library on CodePlex (silverlight.codeplex.com) that has a bunch of handy controls such as DockPanel, ViewBox and BusyIndicator.
Also has a comprehensive samples app which lists the controls included but includes examples of styling, templating, selection, events, databinding etc for each control. Pretty handy!
Jeff showed us a really nice styled, templated app called Bugaholic he wrote that looks a lot like the Zune client.
http://www.jeff.wilcox.name/2010/05/my-childwindow-design/
Einar covered some unit testing, Jeff wrote the Silverlight Unit Testing framework so we saw a bit of that to end with.

Labels: ,

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home