Business value with Silverlight
Download
Report
Transcript Business value with Silverlight
Business value with Silverlight
READING, WRITING, BINDING, VALIDATING
AND VISUALISING YOUR DATA
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
Business Value?
Foundations of Silverlight: XAML
What is a Silverlight App?
A parallel universe of dlls
System.Windows.Controls
classes arranged together
(usually via XAML)
Web Page
Silverlight
host
XAML - a format for
building objects via XML
WPF, Silverlight, WWF etc
Application
(App.xaml)
Why would you bother
with XAML?
Designer support
Designer support
UserControl
(Page.xaml)
FoS: Dependency Properties
Silverlight objects are
DependencyObjects
DependencyObjects have
DependencyProperties
Child 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
WPF
Templates 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
Easing
Colours, Positions, Opacities, Sizes
Makes things look “natural”
Subtle animations are good for business
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
Back end
Database
Business Logic
Domain model
Web Server
Host Page
Web Service for
Data
REST?
Silverlight client
Data binding
Validation
Visualisation
User
Armed with key
data
Leverages
synergies
Pays you
money
Data Access
Web Services
REST
SQL Server Data Services
AKA Astoria
See Diagram
Sockets (push data)
All data operations are
asynchronous
(BeginBlah, EndBlah)
DEMO
Database
LINQ to Entities model
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 up
Bindings 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.com
All comments, questions, donations totally
appreciated: [email protected]