570 likes | 727 Views
Building RIA’s With Silverlight 2. Gill Cleeren Microsoft Regional Director MVP ASP.NET Software Architect Ordina Belgium gill.cleeren @ ordina.be www.snowball.be – www.codeflakes.net. Agenda. Rich Internet Applications Getting Started with Silverlight 2 on .net
E N D
Building RIA’sWith Silverlight 2 Gill CleerenMicrosoft Regional Director MVP ASP.NET Software Architect Ordina Belgium gill.cleeren@ordina.be www.snowball.be – www.codeflakes.net
Agenda • Rich Internet Applications • GettingStartedwith Silverlight 2 on .net • Silverlight 2 deepdive: • Controls • Layout • Brushes and transformations • Networking • Databinding • Styles and content templates • Deepzoom • Showcase • Summary
A littlehistory Q2 08 Silverlight 2 Beta 2 Silverlight 1.0 & Silverlight 1.1
Characteristics of an RIA • Web deployment • Broad client reach • Secure sandboxed environment • Rich UI experiences beyond server generated HTML • Highly capable UI model • Signifigant client-side application logic • Highly productive development environment
Microsoft Silverlight is a cross-browser, cross-platform implementation of .NET for building and delivering the next generation of media experiences & rich interactive applications for the Web.
.NET + Silverlight • Cross-platform & cross-browser plugin • Works with Safari, Firefox and IE on Mac & Windows • Will work with FireFox, Konquerer and Opera on Linux • 4.3MB with a fast, easy install process • Highly productive development Framework • Multi-language support – VB, C#, JavaScript, Python, Ruby • Rich class library of functionality that can be used • Great tools with Visual Studio & Expression
.NET for Silverlight & the Desktop • .NET for Silverlight is a subset of the full .NET Framework • Targetted support for RIA and Media scenarios • Common core .NET development model • Common APIs across both browser and desktop scenarios • Common WPF UI programming model across both • Development and Designer tools are the same • Compatible subset of WPF UI framework
What You'll Need: • Install the following: • Silverlight 2 Beta1 (orbeta 2, available in June) • Silverlight Tools for Visual Studio 2008 Beta 1 • Expression Blend 2.5 March Preview • Everything you need is at www.silverlight.net • Links to downloads & docs • VS object browser a great way to view APIsoruse Reflector
Building Hello World demo
Controls <Button x:Name=“MyButton” Content=“Push Me” Width=“150” Height=“50” /> Button b = new Button(); b.Width = 150; b.Height = 50; b.Content = “Push Me"; Re-usable UI elements that encapsulate UI and behavior and enable re-use and composition
Some Built-in Beta1 Controls • High-Level Controls: • Calendar • DataGrid • Slider • DateTimePicker • Shapes: • Ellipse • Rectangle • Line • TextBlock • Path • Core Controls: • Border • Image • MediaElement • MultiScaleImage • ToolTip • ScrollViewer • Navigation Controls: • HyperlinkButton • Popup • Form Controls: • TextBox • Button • Toggle/Repeat Button • CheckBox • RadioButton • ListBox • Layout Controls: • StackPanel • Grid / GridSplitter • Canvas
x:Name <Button x:Name=“MyButton”/> public void Page_Loaded(sender, MouseEventArgs e) { MyButton.Content = “Push Me!”; } • Name your controls so you can use it in code • Visual Studio automatically declares field for all x:name elements
Wiring Up Event Handlers <Button x:Name=“MyButton” Content=“Push Me” Click=“MyButton_Click“/> public void MyButton_Click(object sender, RoutedEventArgs e) { // todo: add code } • Event handlers can be wired up declaratively in XAML: • Or explictly within the code-behind file • VB – using the "Handles" keyword • C# -- programmatically within the Page_Loaded event handler
Controls demo
Layout • Silverlight and WPF support concept of Layout Panels • Canvas • StackPanel • Grid • Layout system is customizable • TilePanel • RadialPanel • Etc.
The Canvas The Rectangle Canvas <Canvas Width="250" Height="200"> <Rectangle Canvas.Top="25" Canvas.Left="25" Width="200" Height="150" Fill="Yellow" /> </Canvas> Is a Drawing Surface Children have relative positions
StackPanel <StackPanel Orientation="Vertical"> <Button>Button 1</Button> <Button>Button 2</Button> </StackPanel>
Grid Panel <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="100"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="75"/> <RowDefinition Height="*"/> <RowDefinition Height="85"/> </Grid.RowDefinitions> <Button Grid.Column="1" Grid.Row="1" Content=“Button 1" Margin="8,8,8,8"/> <Button Grid.Column="1" Grid.Row="2" Content=“Button 2" Margin="8,8,8,8"/> </Grid>
Layout demo
Brushes • Determines how objects are painted • For painting objects (e.g. Fill) • For painting of lines (e.g. Stroke) • Brush options include: • Solid color brushes • Gradient brushes • Image brushes • Video brushes
Brushes <Rectangle Width="200" Height="150" > <Rectangle.Fill> <SolidColorBrush Color="Black" /> </Rectangle.Fill> </Rectangle> <Rectangle Width="200" Height="150" Fill="Black" /> <Rectangle Width="200" Height="150" Fill="#FFFFFF" /> • <SolidColorBrush /> • Support creation by name • 141 named colors supported (e.g. Blue, Red, Green) • Supports #FFFFFF or #FFFFFFFF syntax as well
Brushes <Rectangle Width="200" Height="150"> <Rectangle.Fill> <LinearGradientBrushStartPoint="0,0" EndPoint="1,1"> <LinearGradientBrush.GradientStops> <GradientStop Color=“Blue" Offset="0" /> <GradientStop Color="Black" Offset="1" /> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> • <LinearGradientBrush /> • Start and Stop are to set angle as numbers • Gradient Stops are the different color points
Transformations • All elements support them • Transform Types • <RotateTransform /> • <ScaleTransform /> • <SkewTransform /> • <TranslateTransform /> • Moves • <MatrixTransform /> • Scale, Skew and Translate Combined
Transformations <TextBlock Text="Hello World"> <TextBlock.RenderTransform> <RotateTransform Angle="45" /> </TextBlock.RenderTransform> </TextBlock> Hello World
Rich Networking Options Available HTTP WS* / SOAP REST RSS Sockets Cross Domain Networking Support Available
Networking demo
Databinding • Enable clean view/model separation and binding • Change UI presentation wtihout code-behind modifications • Works with any object that implements IEnumerable • Arrays, Lists, Collections, etc. • Binding Expressions can be one way or two way • INotifyPropertyChange change notifications supported
Databinding demo
Styles • Allow look and feel of a control to be defined externally • Conceptually similar to Stylesheets with HTML • Support encapsulating style properties and control templates • Control templates particularly powerful (will see soon) • Can be defined either within UI XAML files or App.xaml • App.xaml allows use across all files in application
Content Templates • Allow the visual tree of a control to be completely replaced and/or customized however you want • Override not only the look and style – but also the feel • Interaction behaviors, animations, etc. • Enable clean designer/developer workflow
Image Deep Zoom • Provides seamless viewing & zooming of huge images • Loads only the data necessary to show the part of an image the user is viewing • Effectively turns a large image into an efficiently scaling vector
Image Deep Zoom • Preprocessing tool breaks image into 256 x 256 tiles • Then generates pyramids of tiles at lower resolutions
Deep Zoom – How does it work? • When the image is displayed on the client the lowest resolution tiles are shown first • Then as the higher quality tiles are downloaded, they are smoothly blended in
Deep Zoom – How does it work? • When the image is displayed on the client the lowest resolution tiles are shown first • Then as the higher quality tiles are downloaded, they are smoothly blended in
Deep Zoom – How does it work? • When the image is displayed on the client the lowest resolution tiles are shown first • Then as the higher quality tiles are downloaded, they are smoothly blended in
Image Deep Zoom • Exposed through the MultiScaleImage • Preprocessing tool outputs image tiles and XML description file