reading, writing, binding, validating and visualising your data business value with silverlight

Post on 26-Dec-2015

225 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA

Business value with Silverlight

Introductions

Me I work at Datacom, on a large range of projects, primarily user interfaces I have been yearning to try Silverlight but haven’t had the chance at work My blog is at www.robfe.com. It’s a bit... new?

You Who’s done

Silverlight Flash Wpf Astoria ASP MVC REST LINQ to Entities LINQ C#

The Agenda

Foundation XAML DependencyObjects and DependencyProperties Templates, Styles & Resources Layout

Working with Data Access (with Web Services & REST) Binding Validation Visualisation

Foundations of Silverlight: XAML

What is a Silverlight App? A parallel universe of dlls System.Windows.Controls

classes arranged together (usually via XAML)

XAML - a format for building objects via XML WPF, Silverlight, WWF etc

Why would you bother with XAML? Designer support Designer support

Web Page

UserControl

(Page.xaml)

FoS: Dependency Properties

Silverlight objects are DependencyObjects DependencyObjects have

DependencyPropertiesChild objects can

“inherit” properties from their parents Great for layout Actually, you can set any

DependencyProperty on any DependencyObject (but there might be no point)

FoS: Styles and Templates

Styles can be used to “set” values on existing object trees A bit like CSS Bindings only work in

WPFTemplates can

replace the object tree itself ListView is the most

common place to do this

We’ll go into this...

FoS: Layout and Animations

Layout It’s got some sweet layout controls

Grid, Canvas, StackPanel No more cross browser issues

Animations It’s got some sweet animation support. In XAML you declare the start and end values of

properties Colours, Positions, Opacities, Sizes

Easing Makes things look “natural”

Subtle animations are good for business

With Easin

g

No Easin

g

With Easin

g

No Easin

g

Business Scenarios for Silverlight

90% of what we do has a central data store Silverlight has to get its

data over http (no database connection)

Silverlight > ASPX etc Stateful Easy to bind Validation can be very

user friendly You can make it look

totally hot. Rich visualisations

Data Access

Web ServicesREST

SQL Server Data Services AKA Astoria

See DiagramSockets (push data)All data operations

are asynchronous (BeginBlah, EndBlah)

DEMO

Database

DataService

Http

DataServiceContext(Client)

Data Binding

Databinding in Silverlight is very good Hierarchy Navigation DataContext inheritance Two Way

XAML:<TextBox x:Name="txt1" Text="{Binding 'Name', Mode=TwoWay}"/>

Code:txt1.SetBinding(TextBox.TextProperty, new Binding("Name"){Mode=BindingMode.TwoWay});

DEMO

Data Validation

The BindingValidationError event bubbles upBindings support single property validation:

ValidatesOnExceptions: Cause a validation error instead of throwing the exception

NotifyOnValidationError: Raise the BindingValidationError event if there is a binding error

We can throw exceptions from within our property setters.

DEMO

Data Visualisation

Visual Properties can be databound Canvas.Left, Grid.Row etc

The visual elements in SL/WPF are really easy to work with Great layout options All visual elements are objects (no more

DrawRectangle()) Templates also provide a lot of power

DEMO

Tips, Tricks, Workarounds

Astoria Client Cast your IEnumerable<T> queries into

DataServiceQuery<T> to get access to Expand and BeginExecute

When saving related records / foreign keys, you have to manually call AddLink on your context

Astoria Service Set config.UseVerboseErrors=true while debugging to

get error messages out of your svc Test it with Firebug/Fiddler/Charles config.SetEntitySetAccessRule("*",

EntitySetRights.All);

Tips, Tricks, Workarounds continued

Expression Blend Loads of draggy droppy support for templates, bindings,

styles, gradients & paths. All the stuff you don’t want to hand code.

You can give a user control a “Design time size” You have to reference a different DLL to get more controls

Don’t try and use DatePickerTextBox

Silverlight Sometimes your browser will cache your XAP – delete temp

files if you don’t see your changes reflected Really good JavaScript bridge If you’re accessing services not on your domain, make sure

you read up on cross domain JavaScript.

Thank you

Questions?Feature Requests?Slides & Solution will be on my blog:

www.robfe.comAll comments, questions, donations totally

appreciated: rob@robfe.com

top related