Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Building RIA Apps with Silverlight

Wird geladen in …3

Hier ansehen

1 von 143 Anzeige

Weitere Verwandte Inhalte

Diashows für Sie (20)


Ähnlich wie Building RIA Apps with Silverlight (20)


Aktuellste (20)

Building RIA Apps with Silverlight

  1. 1. Silverlight Intermediate(Developing RIA Apps with Silverlight)<br />Aniruddha Chakrabarti<br />.NET and Integration CoE<br />
  2. 2. Intro …<br />Get to know each other – All<br />What you want to know – All<br />Course Objective and Summary – Aniruddha<br />Logistics<br />Schedule<br />Take Away <br />
  3. 3. Agenda<br /><ul><li>RIA and Web 2.0, RIA tools
  4. 4. Silverlight – History, Overview and Architecture
  5. 5. Controls, Panel, Layout, Transform, Brush …
  6. 6. Resource, Style, Control Template, Data Template
  7. 7. Data Binding, Data Annotation, Isolated Storage
  8. 8. Full Screen and Out of Browser Support
  9. 9. HTML Bridge: Interaction between managed code & JavaScript
  10. 10. Silverlight-enabled WCF Service
  11. 11. What’s new in Silverlight 4</li></li></ul><li>What is RIA<br /><ul><li>RIA stands for Rich Internet Application
  12. 12. “Rich Internet Applications (RIAs) are web applications that have many of the characteristics of desktop applications, typically delivered either by way of a site-specific browser, via a browser plug-in, or independently via sandboxes or virtual machines” – Wikipedia</li></ul>The term RIA introduced in white paper in Mar 2002 by Macromedia (now Adobe),though the concept had existed for many years earlier under names such as:<br />Remote Scripting, by Microsoft, circa 1998 <br />X Internet, by Forrester Research in October 2000 <br />Rich (web) clients <br />Rich web application <br />
  13. 13. RIA Characteristics<br /><ul><li>Improved usability via rich and creative user interface that provides an interactive rich experience - similar to desktop rich client applications. Support for Audio, Video.
  14. 14. Modular and loosely coupled web app architecture that supports flexibility and user-level customization
  15. 15. High-performing rich and interactive web-based apps.
  16. 16. Collaboration platform to share information among diverse and geographically separate groups.
  17. 17. Platform-independent technology that is supported on cross-platform (support for many OS), cross-browser and cross-device (available on computers, mobile devices).</li></li></ul><li>RIA tools & frameoworks in market<br />Source: http://en.wikipedia.org/wiki/List_of_rich_internet_application_frameworks<br />
  18. 18. RIA Landscape – Other tools in Market<br />Flash<br />Multimedia platform used to add animation, video, and interactivity to Web pages. Frequently used for advertisements and games.<br />Manipulates vector and raster graphics to provide animation of text, drawings, and still images. Supports streaming of audio and video. Can capture user input via mouse, keyboard, microphone, camera. <br />Coded in an Object-oriented language called ActionScript.<br />May be displayed on various computer systems and devices, using Adobe Flash Player, which is available free of charge for common Web browsers, some mobile phones and few devices.<br />Flex<br />SDK for the development and deployment of cross-platform rich Internet applications based on the Adobe Flash platform. <br />Can be written using Adobe Flash Builder or by using the freely available Flex compiler from Adobe.<br />
  19. 19. RIA Landscape – Other tools in Market<br />AIR (Adobe Integrated Runtime)<br />Cross-platform runtime environment developed by Adobe Systems for building rich Internet applications using Adobe Flash, Adobe Flex, HTML, or Ajax, that can be deployed as desktop applications.<br />Development Environment<br />HTML/Ajax, either via Adobe's own Dreamweaver CS4 (In addition to Dreamweaver CS3), another HTML editor or a normal text editor in conjunction with the AIR SDK<br />Adobe Flash Builder (formerly Adobe Flex Builder) <br />Flash CS4<br />
  20. 20. RIA Landscape – Other tools in Market<br />Java Applet / JavaFX<br />Java platform for creating and delivering RIAs that can run across wide variety of connected devices. Enables building apps for desktop, browser and mobile phones. TV set-top boxes, gaming consoles, Blu-ray players and other platforms are planned.<br />Developers use a statically typed, declarative language called JavaFX Script; Java code can be integrated into JavaFX programs. JavaFX is compiled to Java bytecode, so JavaFX applications run on any desktop and browser that runs the Java Runtime Environment (JRE) and on top of mobile phones running Java ME.<br />On desktop, the current release supports Windows XP, Vista and Mac OS X OS. JavaFX 1.2 would support Linux and OpenSolaris<br />On mobile, JavaFX is capable of running on multiple mobile operating systems, including Symbian OS, Windows Mobile, and proprietary real-time operating systems.<br />
  21. 21. What is Silverlight<br /><ul><li>cross-browser, cross-platform, and cross-deviceplug-in for delivering next generation of .NET-based media experiences and rich interactive apps for Web.
  22. 22. Supported by small download that installs in seconds
  23. 23. Subset of WPF and .NET Framework
  24. 24. Provides compelling graphics that users can manipulate directly in browser - drag, turn, zoom. Streams video, audio.
  25. 25. Reads data and updates the display without interrupting user by refreshing the whole page.
  26. 26. Supported on multiple platforms and browsers
  27. 27. Windows - Win 7, Vista, XP, Server 2008, Server 2003, 2000
  28. 28. Mac - OS 10.4.8+ (PowerPC) & OS 10.4.8+ (Intel-based)
  29. 29. Linux - Supported on Linux by Mono project (Novel)
  30. 30. Browsers - IE 6/7/8, Firefox 1/2/3, Safari 2/3 (Chrome from S4)</li></li></ul><li>History of Silverlight<br /><ul><li>Microsoft showed first version along with WPF at MIX conference in March 2006 – was then called WPF/E (Windows presentation Foundation Everywhere)
  31. 31. Was later renamed to Silverlight - Silverlight 1.0 was released in May 2007 at MIX 2007 by Scott G.
  32. 32. Less no of UI Controls, No support for .NET (functionality has to be coded in JavaScript), no XAP package
  33. 33. Silverlight 2.0 was released in October 2008
  34. 34. Silverlight 3.0 was released in late 2009.
  35. 35. Silverlight 4.0 was released on April 2010 (soon after .NET 4, Visual Studio 2010 release)</li></li></ul><li>Features Supported by Silverlight<br /><ul><li>WPF and XAML - Includes subset of WPF - greatly extends elements in browser. WPF allows immersive graphics, animation, media, and other rich client features, extending browser-based UI possible with HTML. XAML provides a declarative markup syntax for creating elements.
  36. 36. Extensions to JavaScript- Provides extensions to the universal browser scripting language that provide control over the browser UI, including ability to work with WPF elements.
  37. 37. Cross-browser, cross-platform support - Runs the same on all popular browsers and on popular platforms.
  38. 38. Integration with existing applications - Integrates seamlessly with existing JavaScript and ASP.NET AJAX code to complement existing functionality.
  39. 39. Access to the .NET Framework programming model – could be created using dynamic languages such as IronPython as well as languages such as C# and VB.
  40. 40. Networking support - Includes support for HTTP over TCP. You can connect to WCF, SOAP, or ASP.NET AJAX services and receive XML, JSON, or RSS data.
  41. 41. LINQ – Includes LINQ – enables to program data access using intuitive native syntax and strongly typed objects in .NET Framework languages. </li></li></ul><li>Which UI Platform to use<br />Thick Client<br />WPF<br />XBAP (XAML Browser Apps)<br />Win Forms<br />Thin Client<br />ASP.NET Web Forms<br />ASP.NET Ajax<br />ASP.NET MVC<br />ASP.NET Dynamic Data<br />RIA<br />Silverlight (with ASP.NET Web Forms)<br />Silverlight (with ASP.NET MVC)<br />Silverlight (with ASP.NET Web Forms/MVC + Ajax)<br />
  42. 42. Architecture<br />
  43. 43. Silverlight Architecture<br /><ul><li>Silverlight platform as a whole consists of two major parts, plus an installer and update component –
  44. 44. Core presentation framework - Components and services oriented toward the UI and user interaction, including user input, lightweight UI controls for Web apps, media playback, data binding, vector graphics, text, animation, and images. Also includes XAML for specifying layout.
  45. 45. .NET Framework for Silverlight - A subset of the .NET Framework that contains components and libraries, including data integration, extensible Windows controls, networking, base class libraries, garbage collection, and CLR.
  46. 46. Installer and updater - An installation and update control that simplifies the process of installing the application for first-time users, and subsequently provides low-impact, automatic updates. </li></li></ul><li>Silverlight Architecture (Cont’d)<br />
  47. 47. Core Presentation Framework<br /><ul><li>Silverlight core presentation framework is subset of WPF. Provides libraries and utilities necessary to parse Silverlight XAML files, present UI to browser, and handle interaction from user.</li></li></ul><li>.NET Framework for Silverlight<br />
  48. 48. Silverlight Plug-in<br />
  49. 49. Browser Add on <br />
  50. 50. Silverlight Tools<br /><ul><li>Visual Studio (with Silverlight Tools for VS 2008/VS2010)
  51. 51. Silverlight developer runtime – Unlike Silverlight runtime (installed by end users), has error messages for debugging.
  52. 52. Silverlight SDK and Silverlight Tools
  53. 53. Expression Blend</li></li></ul><li>Creating new Silverlight Project<br />
  54. 54. Application and Programming Model<br />
  55. 55. Application and Programming Model<br />Provides two distinct models for app development:<br />Managed API for Silverlight - uses code running on CLR for Silverlight. Could be used with compiled languages (VB, C#) or dynamic languages such (IronPython, IronRuby)<br />JavaScript API for Silverlight - uses JavaScript code interpreted by the browser.<br />Both can not be used at the same time within a single instance of the Silverlight plug-in. <br />However, you can implement a splash screen that uses the JavaScript API and then transitions to the managed API when your application has loaded. <br />Managed API provides significantly more functionality than JavaScript API. Managed API apps have access to lightweight version of .NET Framework. <br />JavaScript API, however, has access only to the Silverlight presentation core and the browser JavaScript engine.<br />
  56. 56. Managed Programming & Application Model<br />Managed API enables you to bundle managed assemblies and resource files into application package (.xap) files. Silverlight plug-in is responsible for loading an application package and extracting its contents. <br />Application package must contain an assembly with a class derived from Application. Application class encapsulates interaction between appand the Silverlight plug-in. Also provides application lifetime events & resource management. <br />Silverlight documentation uses “application model” to refer to application packaging and the common functionality encapsulated by the Application class. <br />
  57. 57. Application Class<br /><ul><li>Application class encapsulates services commonly required by Silverlight-based app, like life-cycle event notification and interaction with Silverlight plug-in.
  58. 58. Events
  59. 59. Startup, Exit, UnhandledException
  60. 60. Property
  61. 61. Current: Returns the current application object.
  62. 62. Host: Allows code to interact directly with the Silverlight plug-in that hosts it.
  63. 63. RootVisual: To display the application UI, RootVisual is set at Startup event handler (represents the entry point of application code in the Silverlight plug-in life cycle).</li></li></ul><li>Application Class Exampale<br />
  64. 64. Application Structure<br />Silverlight apps are deployed as .xap package (xaml app package)<br />An application package is a zip file (compressed using the Deflate algorithm) that has a .xap file extension.<br />For Silverlight-based apps using the managed API, build process generates an application package.<br />While embedding Silverlight plug-in in web page, specify app package that the plug-in should download. Plug-in uses a manifest file in application package to identify the application class to instantiate. This class is known as the entry point of your application, and it must derive from the Application class.<br />
  65. 65. Application Structure (Cont’d)<br />
  66. 66. XAP Package<br />A XAP App package contains the following - <br />One AppManifest.xaml file, which identifies the packaged assemblies and the application entry point. <br />One application assembly, which includes your application class.<br />Zero or more library assemblies.<br />Zero or more loose resource files, such as images or video files.<br />
  67. 67. Application Manifest<br /><Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" <br />EntryPointAssembly="Silverlight3App" EntryPointType="Silverlight3App.App" RuntimeVersion="3.0.40818.0"><br /> <Deployment.Parts><br /> <AssemblyPart x:Name="Silverlight3App" Source="Silverlight3App.dll" /><br /> </Deployment.Parts><br /></Deployment><br />AppManifest.xaml file is typically generated by build process, and uses XAML markup to declare a Deployment object.<br />EntryPointAssembly and EntryPointType attributes to identify the application entry point. <br />RuntimeVersion attribute to identify required version of Silverlight. <br />
  68. 68. Build and Deploy<br />
  69. 69. Silverlight Assemblies<br /><UserControl<br />xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"<br />xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input"<br />xmlns:d="http://schemas.microsoft.com/expression/blend/2008" <br />xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" <br />xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"<br />xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"<br /> x:Class="TestSilverlightApp.MainPage"<br /> Width="440" Height="480" FontSize="13.333" FontFamily="Arial"><br />
  70. 70. .NET Framework Assemblies<br /><ul><li>Silverlight - C:rogram Fileseference Assembliesicrosoftrameworkilverlight3.0
  71. 71. Silverlight SDK - C:rogram Filesicrosoft SDKsilverlight3.0ibrarieslient</li></li></ul><li>.NET Framework for Silverlight<br /><ul><li>Core CLR: Core part of CLR customized for RIA
  72. 72. Small BCL: Small part of Base Class Library customized for RIA</li></li></ul><li>Controls<br />
  73. 73. Silverlight Controls Hierarchy<br />
  74. 74. Silverlight Controls<br /><ul><li>Button
  75. 75. ToggleButton
  76. 76. TextBox
  77. 77. PasswordBox
  78. 78. TextBlock
  79. 79. CheckBox
  80. 80. RadioButton
  81. 81. ListBox
  82. 82. ComboBox
  83. 83. Slider
  84. 84. ProgressBar</li></ul>System.Windows<br />
  85. 85. Silverlight Controls (Image, Audio, Video)<br /><ul><li>HyperlinkButton
  86. 86. Image
  87. 87. MediaElement</li></ul>System.Windows<br />
  88. 88. Silverlight Controls<br /><ul><li>Calendar
  89. 89. DatePicker
  90. 90. TabControl
  91. 91. TreeView</li></ul>xmlns:controls="clr-namespace:System.Windows.Controls;<br />assembly=System.Windows.Controls"<br /><controls:Calendar /><br />
  92. 92. Silverlight Controls<br /><ul><li>DataGrid</li></ul>xmlns:data="clr-namespace:System.Windows.Controls;<br />assembly=System.Windows.Controls.Data"<br /><data:DataGrid Height="100" x:Name="dgAssemblies"/><br />
  93. 93. Silverlight Controls<br /><ul><li>Label</li></ul>xmlns:dataInput="clr-namespace:System.Windows.Controls; assembly=System.Windows.Controls.Data.Input"<br /><dataInput:Label Content="This is a label"></dataInput:Label><br />
  94. 94. Unique Silverlight Controls<br /><ul><li>AutoCompleteBox
  95. 95. Populate ItemsSource property for the values
  96. 96. ValidationSummary (similar to ASP.NET)</li></ul>xmlns:dataInput="clr-namespace:System.Windows.Controls; assembly=System.Windows.Controls.Data.Input"<br /><input:AutoCompleteBox/><br />
  97. 97. Not Supported Controls<br /><ul><li>Silverlight does not support these controls
  98. 98. ListView
  99. 99. Expander</li></li></ul><li>Layout, Input and Panels<br />
  100. 100. Layout System<br />Silverlight plug-in defines area that Silverlight-based appis displayed in – Embed plug-in in a host HTML page; <br />Either position plug-in somewhere inline in HTML page display or have plug-in take up entire HTML page. Two frames of reference when positioning Silverlight objects: <br />Within the plug-in: Position objects on the Silverlight surface within the plug-in’s bounding box. Most of the layout overviews describe this type of positioning.<br />Within the HTML: The entire plug-in and all the objects positioned within it are subject to where you place the plug-in in HTML. <br />
  101. 101. Layout related properties<br />Margin (of type Thickness)<br />Padding (of type Thickness)<br />HorizontalAlignment<br />Left, Right, Center (Default), Stretch<br />VerticalAlignment<br />Bottom, Top, Center (Degault), Stretch<br />HorizontalContentAlignment<br />Left, Right, Center (Default), Stretch<br />VerticalContentAlignment<br />Bottom, Top, Center (Degault), Stretch<br />Zindix (for Canvas only)<br />Margin<br />Padding<br />Margin<br />Padding<br /><Button Height="120" Width="180" Content="Hello"Margin="50" Padding="40" /><br /><Button Height="120" Width="180" Content="Hello"Margin="20,40,60,80" Padding="10,30,50,70" /><br />
  102. 102. Alignment Example<br /><StackPanel x:Name="LayoutRoot" Background="LightBlue" Height="100"><br /><Button Height="40" Width="90" Content="Hello"></Button><br /></StackPanel><br /><Grid x:Name="LayoutRoot" Background="LightBlue" Height="100"><br /><Button Height="40" Width="90" Content="Hello"HorizontalAlignment="Right"VerticalAlignment="Bottom"><br /> </Button><br /></Grid><br /><Grid x:Name="LayoutRoot" Background="LightBlue" Height="130"><br /><Button Height="120" Width="180" Content="Hello"></Button><br /></Grid><br /><Grid x:Name="LayoutRoot" Background="LightBlue" Height="130"><br /><Button Height="120" Width="180" Content="Hello"HorizontalContentAlignment="Right"VerticalContentAlignment="Bottom"></Button><br /></Grid><br />
  103. 103. Layout with Panels - Canvas<br /><ul><li>Simplest among the Panels
  104. 104. Positions child elements based on absolute positions.
  105. 105. Uses Canvas.Left, .Top and .Zindex (determines the z-order of the element) attached property for positioning
  106. 106. z-order of an object determines whether the object is in front of or behind another overlapping object.
  107. 107. By default, the z-order of objects within a Panel is determined by the sequence in which they are declared.
  108. 108. This behavior can be changed by setting Canvas.ZIndex attached property on objects within the Panel.</li></li></ul><li>Layout with Panels - StackPanel<br /><ul><li>Stacks child elements one after another
  109. 109. Setting Orientation = Horizontalstacks elements horizontally. This is the default behavior.
  110. 110. Setting Orientation = Vertical stacks elements vertically.</li></ul>Orientation = Vertical<br />Orientation = Horizontal<br />
  111. 111. Layout with Panels - Grid<br /><ul><li>Grid is the most powerful Panel available – provides complete freedom to developer.
  112. 112. Does not support WrapPanel (unlike WPF)</li></li></ul><li>Layout (Continued)<br /><ul><li>ScrollViewer
  113. 113. Border
  114. 114. Popup</li></li></ul><li>2D Graphics<br />
  115. 115. Transform<br /><ul><li>ScaleTransform
  116. 116. RotateTransform
  117. 117. SkewTransform
  118. 118. TranslateTransform
  119. 119. MatrixTransform
  120. 120. GroupTransform</li></li></ul><li>Transform Example<br /> <Button Margin="10,20,50,50">Scale Transform<br /><Button.RenderTransform><br /><ScaleTransformScaleX="1.5"ScaleY="1.5" /><br /></Button.RenderTransform><br /></Button><br /><Button>Rotate Transform<br /><Button.RenderTransform><br /><RotateTransform Angle="-5" /><br /></Button.RenderTransform><br /></Button><br /><Button>Skew Transform<br /><Button.RenderTransform><br /><SkewTransformAngleX="30"AngleY="5" /><br /></Button.RenderTransform><br /></Button><br /> <br /><Button>Translate Transform<br /><Button.RenderTransform><br /><TranslateTransform X="20" Y="40" /><br /></Button.RenderTransform><br /></Button><br />
  121. 121. Transform Group Example<br /><StackPanelVerticalAlignment="Top" Margin="10" x:Name="LayoutRoot"><br /><Button Margin="50">Group Transform<br /><Button.RenderTransform><br /><TransformGroup><br /><ScaleTransformScaleX="1.5"ScaleY="1.5" /><br /><RotateTransform Angle="-5" /><br /></TransformGroup><br /></Button.RenderTransform><br /></Button><br /></StackPanel><br />
  122. 122. Brushes<br /><ul><li>SolidColorBrush
  123. 123. LinearGradientBrush and RadialGradientBrush
  124. 124. ImageBrush and VideoBrush
  125. 125. WebBrowserBrush (new in SL4)</li></li></ul><li>Gradient Brush Example<br /> <TextBox Background="LightBlue" Height="40" Text="Solid Color Brush"></TextBox><br /><TextBox Height="40" Text="Solid Color Brush"><br /><TextBox.Background><br /><SolidColorBrush Color="LightGreen"></SolidColorBrush><br /></TextBox.Background><br /></TextBox><br /><TextBox Height="40" Text="Linear Gradient Brush"><br /><TextBox.Background><br /><LinearGradientBrush><br /><GradientStop Color="Yellow" Offset="0" /><br /><GradientStop Color="Red" Offset="1" /><br /></LinearGradientBrush><br /></TextBox.Background><br /></TextBox><br /> <br /><TextBox Height="80" Text="Radial Gradient Brush"><br /><TextBox.Background><br /><RadialGradientBrush><br /><GradientStop Color="White" Offset="0" /><br /><GradientStop Color="Blue" Offset=".5" /><br /><GradientStop Color="LightSalmon" Offset="1.5" /><br /></RadialGradientBrush><br /></TextBox.Background><br /></TextBox><br />
  126. 126. Image Brush Example<br /> <TextBox Height="300" Width="400"FontSize="20" Foreground="White"><br /><TextBox.Background><br /><ImageBrushImageSource="Chikmagalur049.JPG"></ImageBrush><br /></TextBox.Background><br /></TextBox><br /> <br />
  127. 127. Video Brush Example<br /> <MediaElement x:Name="videoMediaElement" Source="Wildlife.wmv" Visibility="Collapsed" /><br /><TextBox Height="300" Width="400"FontSize="20" Foreground="LightYellow"<br /> Text="This is using Video Brush"><br /><TextBox.Background><br /><VideoBrushSourceName="videoMediaElement" /><br /></TextBox.Background><br /></TextBox><br /> <br />
  128. 128. Shapes<br />Line<br />Rectangle<br />Eclipse<br />Path<br />
  129. 129. Shapes Example<br /><Line Stroke="Red"StrokeThickness="2" X1="10" Y1="5" X2="270" Y2="5" /><br /><Polyline Points="100,10 10,10 10,50 100,50 250,30" Stroke="Black"StrokeThickness="5" /><br /><Rectangle Height="50" Margin="20" Fill="LightBlue" Stroke="Black"StrokeThickness="2"></Rectangle><br /><Ellipse Height="50" Fill="LightGreen" Stroke="Black"StrokeThickness="5" /><br /> <br /><Polygon Points="30,20 50,100 10,100 30,20" Stroke="Red" Fill="LightCyan"StrokeThickness="5" /><br />
  130. 130. Pixel Shader Effect<br />Blur Effect<br />Drop Shadow Effect<br /><Button Margin="20"FontSize="20">Drop Shadow Effect<br /><Button.Effect><br /><DropShadowEffect Color="Blue"BlurRadius="10" /><br /></Button.Effect><br /></Button><br /><Button Margin="20"FontSize="20">Blur Effect<br /><Button.Effect><br /><BlurEffect Radius="4" /><br /></Button.Effect><br /></Button><br />
  131. 131. Silverlight Toolkit<br /><ul><li>Controls -
  132. 132. Numeric UpDown
  133. 133. Rating Control
  134. 134. Expander
  135. 135. Time Picker
  136. 136. Time UpDown</li></li></ul><li>Silverlight Toolkit<br /><ul><li>Controls -
  137. 137. Accordian
  138. 138. ViewBox</li></li></ul><li>Silverlight Toolkit<br /><ul><li>Panels
  139. 139. Wrap Panel
  140. 140. Dock Panel</li></li></ul><li>Child Window<br /><controls:ChildWindow x:Class="SL4App.ChildWindow1"<br />xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"<br /> Width="400" Height="300"<br /> Title="ChildWindow"><br /><Grid x:Name="LayoutRoot" Margin="2"><br /><Grid.RowDefinitions><br /><RowDefinition /><br /><RowDefinition Height="Auto" /><br /></Grid.RowDefinitions><br /> <br /><Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23"HorizontalAlignment="Right" Margin="0,12,0,0"Grid.Row="1" /><br /><Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23"HorizontalAlignment="Right" Margin="0,12,79,0"Grid.Row="1" /><br /><StackPanelHorizontalAlignment="Center"VerticalAlignment="Center"><br /><TextBlock>This is a child window</TextBlock><br /><TextBox></TextBox><br /><CheckBox>CheckBox</CheckBox><br /></StackPanel><br /></Grid><br /></controls:ChildWindow><br />ChildWindow1 child = newChildWindow1();child.Show();<br />
  141. 141. Child Window<br />
  142. 142. Resource<br /><ul><li>Resources allow reuse
  143. 143. Resources are stored in ResourceDictionary
  144. 144. Resource property is defined in FrameworkElement, so each class deriving from it can store resources.
  145. 145. Could be stored in Page or in App.xaml
  146. 146. Only StaticResource Markup Extenstion is supported, DynamicResource is not supported .</li></li></ul><li>Resource, Style and Template<br />
  147. 147. Resource Example (1)<br />
  148. 148. Resource Example (2)<br />
  149. 149. Creating a Resource in Blend<br />Define the Resource<br />Refer the Resource<br />
  150. 150. Style<br /><ul><li>Similar to CSS in HTML.
  151. 151. A Style is nothing but a collection of property setters for a control.
  152. 152. Every property of a FrameworkElement (as long as it is a DependencyProperty) can be set through a Style.
  153. 153. Supports BasedOn and TargetType similar to WPF.
  154. 154. Referenced using StaticResource Markup Extension.
  155. 155. Priority of Style is from bottom to top in hierarchy (with bottom one with highest priority).</li></li></ul><li>Style Example<br />
  156. 156. Template<br />Template allow separate appearance of control from it’s behavior and logic.<br />Button: appearance is the raised area that you can press, and the behavior is the Click event that gets raised in response to a click.<br />The source code for every control is completely separated from its default visual tree representations.<br />Template allows to completely replace an element’s visual tree, while keeping all of its functionality intact.<br />Default visuals for every Control in WPF are defined in templates (and customized for each Windows theme). <br />There are three types of Templates<br />ControlTemplate<br />DataTemplate<br />ItemsPanelTemplate<br />
  157. 157. Control Template Example<br />
  158. 158. Template Binding Example<br />
  159. 159. Data Template Example<br />
  160. 160. Data Template Example<br />
  161. 161. Items Panel Template Overview<br />
  162. 162. Data Annotation<br /><ul><li>You can apply attributes to the class or members that specify validation rules, how data is displayed, and set relationships between entity classes.
  163. 163. System.ComponentModel.DataAnnotations namespace contains classes used as data attributes.
  164. 164. By applying these attributes on data class or member, you centralize the data definition and do not have to re-apply the same rules in multiple places.
  165. 165. Could be of three types
  166. 166. Display Attribute – for UI purpose
  167. 167. Validation Attribute
  168. 168. Data Modeling Attribtue</li></li></ul><li>Display Attribute<br /><ul><li>System.ComponentModel.DataAnnotations namespace contains following Display/UI related attributes -
  169. 169. DataTypeAttribute - Specifies a particular type of data, such as e-mail address or phone number.
  170. 170. DisplayAttribute - Specifies localizable strings for data types and members that are used in the user interface.
  171. 171. DisplayColumnAttribute - Designates display and sorting properties when a table is used as a parent table in a foreign key relationship.
  172. 172. DisplayFormatAttribute - Specifies how data fields are displayed and formatted.
  173. 173. FilterUIHintAttribute - Designates the filtering behavior for a column.
  174. 174. UIHintAttribute - Designates the control and values to use to display the associated entity member.
  175. 175. Are automatically applied when used with DataGrid control.
  176. 176. Can manually retrieve display attribute values when data binding by using controls such as Label and DescriptionViewer. </li></li></ul><li>Validation Attribute<br /><ul><li>Following attributes are used to enforce validation rules for data applied to the class or member:
  177. 177. CustomValidationAttribute - Uses a custom method for validation.
  178. 178. DataTypeAttribute - Specifies a particular type of data, such as e-mail address or phone number.
  179. 179. EnumDataTypeAttribute - Ensures that the value exists in an enumeration.
  180. 180. RangeAttribute - Designates minimum and maximum constraints.
  181. 181. RegularExpressionAttribute - Uses a regular expression to determine valid values.
  182. 182. RequiredAttribute - Specifies that a value must be provided.
  183. 183. StringLengthAttribute - Designates max and min number of characters.
  184. 184. ValidationAttribute - Serves as base class for validation attributes.
  185. 185. All validation attributes derive from the ValidationAttribute class. The logic to determine if a value is valid is implemented in the overridden IsValid method.
  186. 186. Are automatically applied when used with DataGrid control. </li></li></ul><li>Data Annotation Example - DisplayAttribute<br />
  187. 187. Data Annotation Example - ValidationAttribute<br />
  188. 188. Data Binding<br /><ul><li>Binding engine gets info from Binding object about:
  189. 189. Source object that contains the data that flows between the source and target. Source can be any CLR object.
  190. 190. Target UI property that displays and possibly allows user changes to the data - can be any DependencyProperty of a FrameworkElement.
  191. 191. Direction of the data flow. The direction is specified by setting the Mode property on the Binding object.
  192. 192. Optional value converter that applies to data as it is passed. Value converter implements IValueConverter.</li></li></ul><li>Data Binding<br />
  193. 193. Data Form<br /><dataFormToolkit:DataForm x:Name="dfPerson" AutoEdit="False"AutoCommit="False" /><br />dfPerson.CurrentItem = new Person{FirstName="Aniruddha",<br />LastName="Chakrabarti",Age=35};<br />
  194. 194. Data Binding<br /><ul><li>Data Context
  195. 195. INotifyPropertyChanged
  196. 196. ObservableCollection, INotifyCollectionChanged
  197. 197. IValueConverter, IMultiValueConverter</li></li></ul><li>Isolated Storage<br /><ul><li>Small section of local storage that is isolated to a specific app and user.
  198. 198. Web apps can save small amounts of persistent data for their purposes.
  199. 199. Cannot be accessed by other apps/users.
  200. 200. Automatically created for Silverlight apps as needed.
  201. 201. Size - 1MB max for Silverlight app.
  202. 202. Exposed via IsolatedStorageFileclass (inSystem.IO.IsolatedStoragens)
  203. 203. Could be accessed via GetUserStoreForApplication and GetUserStoreForSite static methods of IsolatedStorageFile class</li></li></ul><li>Isolated Storage Example<br />
  204. 204. Isolated Storage – Application Settings<br /><ul><li>Isolated storage could be used to store app settings -per-app, per-computer, and per-user settings. 
  205. 205. Scope is determined by full path of app .xap file.
  206. 206. You store application settings using isolated storage through IsolatedStorageSettings class (in System.IO.IsolatedStorage namespace)
  207. 207. Exposes static property for Application & Site level settings.
  208. 208. Implements a dictionary which stores name/value pairs.</li></li></ul><li>Isolated Storage Application Settings Example<br />
  209. 209. Integrating Silverlight in a web page<br /><ul><li>Silverlight plug-in cab be embedded within Web page in one of three ways:
  210. 210. Using an ASP.NET Silverlight server control.
  211. 211. Using the HTML object element.
  212. 212. Using the Silverlight.js helper file.</li></ul><form id="form1" runat="server" style="height:100%;"><br /> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><br /> <div style="height:100%;"><br /> <asp:Silverlight ID="Silverlight1" runat="server" Source="~/ClientBin/Silverlight3App.xap" MinimumVersion="3.0.40307.0" Width="100%" Height="100%" /><br /> </div><br /> </form><br />
  213. 213. Full Screen Support<br /><ul><li>Provides functionality for displaying the Silverlight plug-in in full-screen mode.
  214. 214. Embedded Mode: plug-in displays within the Web browser
  215. 215. Full Screen Mode: plug-in resizes to the current resolution of the screen and displays on top of all other applications, including the browser.</li></li></ul><li>How to enable Full Screen Mode<br /><ul><li>Content.IsFullScreen property determines whether Silverlight plug-in displays as full-screen or embedded.
  216. 216. If IsFullScreen property to true, the Silverlight plug-in displays in full-screen mode; otherwise, the plug-in displays in embedded mode.</li></ul>Registers Application Events<br />Toggles Content.IsFullScreen Mode when mouse left button down event is fired.<br />
  217. 217. Full Screen Example<br />
  218. 218. Out of Browser Support<br /><ul><li>First introduced in SL3
  219. 219. Silverlight-based apps can be configured, so that users can install them from their host Web pages and run them outside the browser.
  220. 220. Configuration is a simple matter of providing additional information about an application. This information is supplied through the application manifest.
  221. 221. Silverlight uses this info to display installation UI, shortcuts for launching the app, and an out-of-browser application window. </li></li></ul><li>Out of Browser Example<br /><ul><li>To set Out of Browser support for app, check Project > Silverlight Project Options > Enable Application Outside Browser option.
  222. 222. OutOfBrowserSettings.xml file is added in Properties folder.</li></li></ul><li>How to enable Out of Browser in VS<br />
  223. 223. Out of Browser settings<br /><OutOfBrowserSettingsShortName="SL4App Application"EnableGPUAcceleration="False"ShowInstallMenuItem="True"><br /> <OutOfBrowserSettings.Blurb>SL4App Application on your desktop; at home, at work or on the go.</OutOfBrowserSettings.Blurb><br /> <OutOfBrowserSettings.WindowSettings><br /> <WindowSettingsTitle="SL4App Application"Height="250"Width="350"Top="100"Left="75"WindowStartupLocation="Manual" /><br /> </OutOfBrowserSettings.WindowSettings><br /> <OutOfBrowserSettings.Icons /><br /></OutOfBrowserSettings><br />
  224. 224. Install Silverlight Out of Browser App<br />
  225. 225. How to whether the app is running Out of Browser<br />if (App.Current.IsRunningOutOfBrowser)<br />{<br />tbMode.Text = "Running Out of Browser";<br />}<br />Else<br />{<br />tbMode.Text = "Running in Browser";<br />}<br />
  226. 226. How to check the Network status<br />if (NetworkInterface.GetIsNetworkAvailable())<br />{<br />tbNetwork.Text = "Connected to Network";<br />}<br />Else<br />{<br />tbNetwork.Text = "Disconnected";<br />}<br />
  227. 227. Save As Dialog (new in SL3)<br /><StackPanelVerticalAlignment="Top" Margin="10" x:Name="LayoutRoot"><br /><TextBlock>Enter text and Click on Save to save text to local file</TextBlock><br /><TextBox Height="100" x:Name="textbox" /><br /><Button Click="Button_Click">Save to local file</Button><br /></StackPanel><br />SaveFileDialog dialog = newSaveFileDialog()<br />{<br /> Filter = "TextFile (*.txt)|*.txt|WordDoc (*.doc)|*.doc",<br />DefaultExt = "*.txt",<br />FilterIndex = 1<br />};<br /> <br />bool? result = dialog.ShowDialog();<br />if (result == true)<br />{<br /> Streamstream = dialog.OpenFile();<br /> using (StreamWriterfileWriter = newStreamWriter(stream))<br /> {<br />fileWriter.Write(textbox.Text);<br />fileWriter.Close();<br /> }<br />}<br />
  228. 228. Save As Dialog (Cont’d)<br />
  229. 229. HTML Bridge<br /><ul><li>Allows to attach Silverlight managed event handlers to HTML controls.
  230. 230. Attach JavaScript event handlers to Silverlight controls.
  231. 231. Expose complete managed types to JavaScript for scripting.
  232. 232. Expose individual methods of managed types to JavaScript for scripting.
  233. 233. Use managed containers for DOM elements such as window, document, and standard HTML elements.
  234. 234. Pass managed types as parameters to JavaScript functions and objects.
  235. 235. Return managed types from JavaScript.</li></li></ul><li>Accessing the HTML DOM<br /><ul><li>Browser library provides access to HTML document, individual DOM elements and allows to invoke scripts from managed Silverlight code.
  236. 236. To access HTML DOM from Silverlight, use following HTML Bridge classes from System.Windows.Browser
  237. 237. HtmlPage - represents the Web page. HtmlPage is static and is the main entry point for all DOM access.
  238. 238. Exposes properties like Document, Plugin, BrowserInformation and Window
  239. 239. HtmlDocument – represents document object.
  240. 240. Provides GetElementById, SetProperty, GetProperty, Submit methods and Body, QueryString properties
  241. 241. HtmlElement - represents DOM elements.
  242. 242. PropvidesSetProperty, GetProperty methods and Id, Children, Parent, CssClass properties.</li></li></ul><li>HTMLPage class example<br />this.DataContext = <br /> HtmlPage.BrowserInformation;<br />
  243. 243. Updating DOM Elements - Example<br />
  244. 244. Interacting with HTML Example<br /><ul><li>Window class provides methods like Alert, Prompt and Confirm methods for dialog boxes.
  245. 245. Navigate and NavigateToBookmark methods for page navigation.
  246. 246. GetProperty and SetProperty methods to read and write properties related to window.</li></li></ul><li>Silverlight-enabled WCF Service<br /><ul><li>WCF server functionality for hosting Web services is not available in Silverlight 3/4. WCF client-side features are generally supported.
  247. 247. Currently Silverlight WCF Framework only supports basicHttpBinding, PollingDuplexHttpBinding and CustomBinding.
  248. 248. Other WCF bindings are not available because they require features that are not supported by the Silverlight client. WSHttpBinding, for example, requires sessions and transactions, which are not supported.</li></li></ul><li>Making a Service Available Across Domain Boundaries<br />To prevent cross-site request forgery, Silverlight allows only site-of-origin communication by default for all requests other than images and media. <br />Example - a Silverlight control hosted at http://contoso.com/mycontrol.aspx can access only services on that same domain by default – for example http://contoso.com/service.svc, but not a service at http://fabrikam.com/service.svc.<br />To enable a Silverlight control to access a service in another domain, the service must explicitly opt-in to allow cross-domain access. <br />Silverlight 4 supports two different mechanisms for services to opt-in to cross-domain access: <br />Place a clientaccesspolicy.xml file at the root of the domain where the service is hosted to configure the service to allow cross-domain access. <br />Place a valid crossdomain.xml file at the root of the domain where the service is hosted. The file must mark the entire domain public. Silverlight supports a subset of the crossdomain.xml schema.<br />
  249. 249. Use clientaccesspolicy.xml file to allow cross-domain access<br />Create a clientaccesspolicy.xml file that allows access to the service. The following configuration allows access from any other domain to all resources on the current domain.<br />
  250. 250. WCF Syndication (RSS and Atom)<br /><ul><li>Mechanism of app integration - server exposes some application data in interoperable format known as a Feed.
  251. 251. Feed - collection of application data that consists of some feed-level metadata (title, author, URL, and other metadata) and a series of feed items.
  252. 252. Within the feed, feed items are ordered in reverse chronological order.
  253. 253. Feed item consists of -
  254. 254. Standard set of item-level metadata (title, URL, creation date, category etc)
  255. 255. Arbitrary amount of application specific data.
  256. 256. Two common types of syndication feeds are Really Simple Syndication (RSS) 2.0 and Atom 1.0 – WCF supports both.</li></li></ul><li>Syndication classes in WCF<br /><ul><li>Located in System.ServiceModel.Web assembly (System.ServiceModel.Syndication ns)
  257. 257. Syndication specific classes - allows to work with feed, feed items, and related metadata in format-independent way:
  258. 258. SyndicationFeed - Represents a top-level feed object, <feed> in Atom 1.0 and <rss> in RSS 2.0.
  259. 259. SyndicationItem - Represents a feed item, for example an RSS <item> or an Atom <entry>.
  260. 260. SyndicationPerson, SyndicationLink, SyndicationCategory
  261. 261. Infrastructure classes - build on WCF web programming model to provide syndication support
  262. 262. Atom10FeedFormatter & RSS20FeedFormatter - feed formatter classes support serializing object model to and from RSS 2.0 and Atom 1.0.</li></ul>RSS<br />Atom<br />
  263. 263. Syndication Object Model<br />
  264. 264. Syndication Feed Example<br />
  265. 265. Create a Basic RSS Feed in WCF<br /><ul><li>Mark Service contract interface with the WebGetAttribute.
  266. 266. Each operation exposed as syndication feed should return Rss20FeedFormatter object.
  267. 267. Use WebHttpBinding instead of basic/wsHttpBinding.
  268. 268. To host service use WebServiceHost (not ServiceHost)</li></li></ul><li>Create a Basic Atom Feed in WCF<br /><ul><li>Mark Service contract interface with the WebGetAttribute.
  269. 269. Each operation exposed as syndication feed should return Atom10FeedFormatter object (instead of Rss20FeedFormatter object).
  270. 270. Use WebHttpBinding instead of basic/wsHttpBinding.
  271. 271. To host service use WebServiceHost (not ServiceHost)</li></li></ul><li>Syndication (RSS and Atom) in IE8<br />
  272. 272. WCF Syndication Example<br />
  273. 273. Using Syndication within Enterprise<br />
  274. 274. Syndication Example<br />
  275. 275. Syndication Example (Cont’d)<br />
  276. 276. Resources<br />
  277. 277. Silverlight 4: What’s new<br />
  278. 278. Printing<br />namespace - System.Windows.Printing<br />classes – PrintDocument<br /> privatevoidbtnPrint_Click(object sender, RoutedEventArgs e)<br /> {<br />PrintDocumentprintDoc = newPrintDocument();<br />printDoc.PrintPage += (s, args) =><br /> {<br />args.PageVisual = LayoutRoot;<br /> };<br /> <br />printDoc.Print("SL4");<br /> }<br />
  279. 279. Printing (Cont’d)<br />args.PageVisual = dgEmps;<br />
  280. 280. RichTextBox control<br />
  281. 281. Clipboard Access<br />Silverlight 4 adds ability to programmatically access clipboard to format and modify data during copy, cut, and paste operations. <br />Copy: <br />Clipboard.SetText(rtb.Selection.Text);<br />Paste:<br />rtb.Selection.Text = Clipboard.GetText();<br />Cut:<br />Clipboard.SetText(rtb.Selection.Text);<br />rtb.Selection.Text = "";<br />
  282. 282. Elevated Trust<br />
  283. 283. Verified / Unverified Application<br />Security Warning for Unverified App<br />Security Warning for Verified App<br />
  284. 284. Silverlight Performance<br />Test on Multiple Platforms and Browsers<br />Set EnableFrameRateCounter to true During Development <br />Use Transparent Background for a Silverlight Plug-in Sparingly <br />When Animating the Opacity or Transform of a UIElement, set its CacheMode<br />Cache Visual Elements when Blending layers using Opacity and Rotating or Stretching Objects <br />Avoid Using Windowless Mode <br />Use Visibility Instead of Opacity Whenever Possible<br />Silverlight Uses Multi-Core in Rendering and Media <br />In Full-Screen Mode, Hide Unused Objects <br />
  285. 285. Silverlight Performance (Cont’d)<br />Do Not Use Width and Height with MediaElement Objects <br />Do Not Use Width and Height with Path Objects <br />Break Up CPU-Intensive Work into Smaller Tasks <br />Break Up Large Application Packages<br />Use Double.ToString(CultureInfo.InvariantCulture) Rather Than Double.ToString() <br />Use Stretch="Fill" When Rendering a Lot of Images<br />Perform time-consuming operations on a background thread using BackgroundWorker class.<br />
  286. 286. Security<br />
  287. 287. Silverlight Security Model<br />By default, Silverlight apps are hosted in browser and run in an environment that restricts access to user's computer . Operate within partial-trust security boundary - called a sandbox. <br />Silverlight apps run in a different security context than the rest of the HTML page that hosts the Silverlight plug-in.<br />Cannot access file system and other system resources in the same way as traditional .NET applications. These actions can still be performed, but they typically must be initiated by the user.<br />Otherwise Silverlight throws SecurityException exception.<br />Despite the restricted execution environment, there are some security considerations when you build Silverlight applications. <br />Silverlight 4 and later applications can be configured to run in elevated trust, which also has security implications. <br />
  288. 288. Silverlight Security<br />Apps operate within a partial-trust security boundary (sandbox). <br />Cannot access the file system and other system resources in the same way as traditional .NET applications. <br />This sandbox environment is enabled by a security model.<br />In the context of security within the application, there are two code types in Silverlight: platform code and application code. <br />Platform code is the API provided by the Silverlight runtime and SDK.<br />Application code is the code that you write by using the platform code.<br />Silverlight runtime can detect code type based on location of code assembly and by checking the public key of assembly. <br />If an assembly is loaded from the Silverlight runtime or SDK installation directory, is signed with a public key from Microsoft, and meets some additional requirements, the assembly can contain platform code. This means that Silverlight application code is never considered to be platform code.<br />
  289. 289. Security Levels<br />Silverlight code has three security levels: Transparent, SafeCritical, and Critical. <br />Transparent Code - code that cannot elevate permissions of call stack. Transparent code can only run with same permission level as its caller. All app code is Transparent code. Has the following characteristics - <br />Cannot contain unverifiable code. All of the code must be verifiably type-safe. <br />Cannot call native code via a P/Invoke or COM interop. <br />Cannot access Critical code or data unless the target is marked SafeCritical.<br /><ul><li>SafeCritical Code - code layer on top of Critical code that helps to ensure calls are safe. Platform code can be Transparent, SafeCritical, or Critical
  290. 290. Critical Code - code that has ability to perform operations outside the security sandbox (such as writing to the file system) </li></li></ul><li>Security Features: Partial Trust<br />
  291. 291. Security Exception <br />
  292. 292. Different Sandbox Modes<br />aaa<br />