READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.
-
Upload
hector-maxwell -
Category
Documents
-
view
223 -
download
0
Transcript of READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.
![Page 1: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/1.jpg)
READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA
Business value with Silverlight
![Page 2: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/2.jpg)
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#
![Page 3: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/3.jpg)
The Agenda
Foundation XAML DependencyObjects and DependencyProperties Templates, Styles & Resources Layout
Working with Data Access (with Web Services & REST) Binding Validation Visualisation
![Page 4: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/4.jpg)
Business Value?
![Page 5: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/5.jpg)
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)
![Page 6: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/6.jpg)
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)
![Page 7: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/7.jpg)
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...
![Page 8: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/8.jpg)
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
![Page 9: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/9.jpg)
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
![Page 10: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/10.jpg)
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)
![Page 11: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/11.jpg)
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
![Page 12: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/12.jpg)
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
![Page 13: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/13.jpg)
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
![Page 14: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/14.jpg)
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);
![Page 15: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/15.jpg)
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.
![Page 16: READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.](https://reader036.fdocuments.in/reader036/viewer/2022062300/56649e2a5503460f94b17e48/html5/thumbnails/16.jpg)
Thank you
Questions?Feature Requests?Slides & Solution will be on my blog:
www.robfe.comAll comments, questions, donations totally
appreciated: [email protected]