Media Video and Audio
The System.Windows.Controls.MediaElement control provides media playback capability in Silverlight 2. It can handle both audio and video in a variety of formats. These are the supported video formats WMVA Windows Media Video Advanced Profile non-VC-1 WMVC1 Windows Media Video Advanced Profile VC-1 ASX Advanced Stream Redirector files extension might be .asx, .wax, .wvx, .wmx, or .wpl Silverlight 3 has enhanced media management supporting high-quality and secured multimedia streaming. The...
M
MACs message authentication codes , 339-341 MainPage class, 422-423, 433-434 MainPage.xaml file, 13, 16, 21, 143, 413-415, 418, 422-423, 427 MainPage.xaml.cs file, 13, 28, 143-145, 416 MainTitle style, 257 Manage Add-ons dialog, 382 ManagedThreadId property, 439 manifest.xml file, 213 MappedUri property, 101, 418 MappingMode property, 237 Margin property, 51, 252 MarkerReached event, 202 Markers property, 200, 205 markup extensions data binding, 34-37 overview, 31 referencing static resources,...
Packaging Images and Media
While you can download images and media file by file, sometimes an application requires a collection of related images or other media before it can start. One example of this is a game that might need a number of images to display scenes, characters, and the background. You can package these resources into a single ZIP archive and download it. After downloading the ZIP file, using the WebClient class perhaps, you can save its stream. Let's revisit the image browser from earlier in the chapter...
Key Files for Silverlight Applications Using IronRuby Dynamic Language
As mentioned earlier, the SDL SDK provides application templates, a set of key files to create Silverlight applications using the dynamic languages IronRuby and IronPython. The templates are available under the script templates ruby and script templates python directories for the IronRuby and IronPython dynamic languages. Let's take a look at the key application files for IronRuby, available as part of the SDL SDK application template. After you extract the SDL SDK, the script templates ruby...
TreeView
The TreeView control implements a tree display where items can be nested within each other, such as you'd see in Windows Explorer with its directory tree. Since this control inherits from ItemsControl, its behavior is much like you'd expect, only the organization of items is different. Figure 3-18 shows what the TreeView looks like with a few of the chapter examples listed from the following XAML lt c TreeViewItem Header Layout Panel Demonstrations IsExpanded True gt lt c TreeViewItem Header...
Combining Multiple Transformations
Although you could use the MatrixTransform class to combine multiple transformations into a single transformation, if you want to combine two or more of the directly supported transformations such as a rotation and a scale , you can use the TransformGroup transform. Figure 7-13 shows the result of combining a ScaleTransform and a RotateTransform together inside a TransformGroup. Figure 7-13. Combining transforms using TransformGroup lt Rectangle Stroke Crimson Fill Crimson Width 50 Height 50 gt...
Introducing the DataGrid Control
The DataGrid control is useful for displaying data in tabular format with rows and columns. It isn't part of the core Silverlight installation, so you must download the Silverlight SDK and distribute the System.Windows.Controls.Data assembly with your application. In order to use DataGrid in XAML, you must make its namespace visible. lt UserControl Width 400 Height 300 Margin 10 gt lt Grid x Name LayoutRoot Background White gt lt c DataGrid lt Grid gt lt UserControl gt You then connect the...
ProgressBar
The ProgressBar control represents the advancement of the defined operation. It also inherits from RangeBase. You can define the following two visual styles for the ProgressBar control using the Islndeterminate property You can have a progress bar with a repeating pattern. You need to set the Islndeterminate property to true. You can have a progress bar that gets filled based on the value. You need to set the Islndeterminate property to false and define the range by setting the Minimum and...
Deep Linking and Search Engine Optimization
If you take a closer look at Figure 14-2, you will notice that the browser address bar includes the page-specific URL, which is http localhost aspx Views HomePage.xaml. When you switch from one page to another page, the Frame control generates the page-specific URL and query string that can be used to go directly to that particular page. As explained earlier, with the use of the Source property of the navigation Frame tag, you can have the default page displayed as the startup page of the...
D Animation
Perspective Transforms in Silverlight 3 that we just learned in Chapter 7 is the next step towards developing 3D Silverlight RIAs. In previous versions of Silverlight, transforms were processed in the X and Y axes using the UIElement's RenderTransform property. Silverlight 3 uses the PlaneProjection class to render 3D-like effects. All elements that derive from UIElement have the Projection property, which allows the element to simulate transformation in a 3D space. In the following XAML code,...
Executing the Text Chat Application
While you are in development mode, before you open the application, visit to start the PolicyServer Windows service and double-click the PolicyServer.exe file to run it. Similarly, visit to start the MessengerServer Windows service and double-click the MessengerServer.exe file to run it. Note that these paths may differ, based on where you set up the application. Two command shell windows should open, indicating that both services are running, as shown in Figure 4-7. Now you are all set to run...
Define the indexhtml File
Last, create an index.html file, which is very similar to what we saw earlier in this chapter. The following is a snapshot of the index.html file lt DOCTYPE html PUBLIC - W3C DTD XHTML 1.0 Transitional EN lt html gt lt title gt Silverlight Animation Sample - with Python lt title gt lt style type text css gt html, body height 100 overflow auto body padding 0 margin 0 background-image background-repeat no-repeat silverlightControlHost position absolute left 100px top 50px lt -- Formatting for DLR...
Binding Modes
There are three possibilities to bind your attribute Bindable false will not display the respective fields in the DataForm. Bindable true, BindingDirection.TwoWay allows the respective fields to be displayed and edited in the DataForm. Bindable true, BindingDirection.OneWay allows the respective fields to be displayed but read only in the DataForm. You can bind class attributes at the class level, which is applicable to all attributes, or at the specific attribute level. If you set up binding...
C
C pointl point2 endPoint command, 224 CacheMode property, 48 Calendar control, 89-90, 269 CalendarButtonStyle property, 89 CalendarItemStyle property, 89 callback function, 333 Cancel property, 445 CancelAsync method, 123 CancelConnectAsync method, 130 CancelEdit method, 168 CancellationPending property, 444-445 Cancelled property, 118 CanGoBack property, 95 CanGoForward property, 95 CanPause property, 200 CanRead parameter, 180 CanReuseTransform property, 340 CanSeek property, 180, 200...
Silverlight Toolkit
The Silverlight Toolkit is a way for the community to develop different Silverlight controls, components, and utilities to be delivered as extensions to the regular Silverlight release. For Silverlight 3, the Silverlight Toolkit includes more than a dozen new controls with full source code, unit tests, samples, and documentation. These controls include an accordion control, chart controls, styling controls, and user input controls that provide enhanced key features. You can get more details on...
Working with the Networking and Offline APIs
Now let's take a brief look at the new networking APIs and offline APIs by incorporating them into the sample application. First remove the default application branding your.application.name XAML code, and then add the following lines of code to represent the application connectivity status Connected Disconnected and application running mode In Browser Out of Browser lt StackPanel Style StaticResource BrandingPanelStyle gt lt TextBlock Text Connectivity Status Style StaticResource...
D Graphics
Silverlight provides two categories of classes for two dimensional graphics shapes and geometries. The System.Windows.Shapes .Shape class forms the base for all shape-related classes. The Shape class inherits directly from FrameworkElement, so it gains all that is provided by the UIElement and FrameworkElement classes. The System.Windows.Media.Geometry class, however, inherits directly from DependencyObject, not from UIElement or FrameworkElement. There are similarities between the two...
GPU Hardware Acceleration
Silverlight 3 also leverages Graphics Processor Unit GPU hardware acceleration to deliver a true high-definition HD media experience in the in-browser and full-screen modes. In Silver-light 1 and 2, media rendering is performed by the software that makes the playback of animations and video files dependent on the capabilities of the CPU of the host PC. This can cause performance issues for complex media files. With Silverlight 3, we can now easily fix this performance problem by taking...
Description Bxi
Returns true if the drop-down box is open, false otherwise. Setting this to true will open the drop-down. Returns true, signifying the user can edit text in the text box. This is a read-only property and will always return true, unless this class is derived and this property is overridden. When set to true, the first match found during the filtering process will appear in the text box. Defaults to false. Specifies the custom method to use for item filtering. When set, the SearchMode property is...
Saving State on the Client
There are two ways to store data on the client through cookies and through isolated storage. The most direct method to save and access cookies is through the HtmlPage.Document class. HtmlPage.Document.Cookies name value expires Saturday, 1-Nov-2009 12 00 00 GMT I won't go into too much detail on working with cookies, since the important thing is how to access them from Silverlight. Isolated storage, however, is much more interesting. It is a mechanism provided by Silverlight to cache data or...
Hash Algorithms and Message Authentication Codes
A hash algorithm transforms a chunk of data into a small, fixed-length set of bytes known as a hash or hash code . As long as the same chunk of data is processed by the same hash algorithm, the resulting hash code will always be the same. If you've heard of CRC codes or digital signatures, you've heard of the result of hash algorithms. Used as a digital signature, a hash code can prove that the data has not changed, since even a small change in the data will result in a completely different...
ScrollBar
The ScrollBar class is visually represented by two RepeatButton controls and a Thumb control that corresponds to the currently selected value within the range. You can see what a horizontal and vertical scrollbar on their own look like in Figure 3-24. Table 3-36 describes ScrollBar's properties. Table 3-36. Key Properties of the Class Property Type Description Orientation Orientation Gets sets the orientation of the scrollbar. Possible values ViewportSize double Specifies the amount of content...
The clientaccesspolicyxml Policy File
As we learned in Chapter 4, the use of the clientaccesspolicy.xml as a security policy file is a Silverlight-specific approach. Its detailed schema supports a more selective and controlled approach, overcoming the disadvantages discussed for the crossdomain.xml file. The following is a sample snapshot of the clientaccesspolicy.xml file lt xml version 1.0 encoding utf-8 gt lt access-policy gt lt cross-domain-access gt lt policy gt lt allow-from lt domain lt allow-from gt lt grant-to gt lt...
Creating and Managing Threads
If you want to execute some code on an alternate thread, you can place the code to execute in its own method and then pass this method to the Thread class's constructor by wrapping the method in a ThreadStart object . We'll use the following method to simulate some work Dispatcher.BeginInvoke delegate statusText.Text Work done. The code for this chapter contains a simple interface used to start a thread executing the doSomething method. You can repeatedly click a button to see the current state...
Custom Error Handling for Better User Experience
Clients' machines must have the Silverlight runtime installed in order to run Silverlight plugins successfully. However, it is very likely that a user's machine may not have Silverlight installed or may contain the older version i.e., the required minimum version is not installed . In this scenario, instead of providing the default Microsoft message to install Silverlight, it would be friendlier if we provided a branded explanatory message and a link to the Silverlight runtime installer. Both...
The Dispatcher
The DependencyObject class acts as the base object for many classes in Silverlight. One important aspect of this class, however, is its single property, Dispatcher. Objects can be modified only on the thread they are created on. Each object, therefore, has a Dispatcher property that provides two important pieces of functionality. For starters, you can test whether an object can be modified from the current thread by calling the CheckAccess method. If the current thread is the same as the one...
HeaderedltemsControl
The HeaderedItemsControl provides a straightforward way to display a list of items with a header area. Figure 3-19 shows what this control looks like when displaying a few color names from a string array via data binding, which we'll look at in Chapter 5 . No selection is supported with this control combine a ListBox with a HeaderedContentControl to accomplish selection . Figure 3-19. The HeaderedItemsControl Table 3-27 defines the key properties of the HeaderedItemsControl class. Table 3-27....
Slider
The Slider control is essentially a scrollbar, but it provides the capability to select a value from within a range. It inherits from RangeBase. Table 3-37 shows its properties. Table 3-37. Properties of the System.Windows.Controls.Slider Class Table 3-37. Properties of the System.Windows.Controls.Slider Class Reverses the direction of increasing values if true down for vertical sliders and left for horizontal sliders. Returns true if the slider currently has input focus. Gets sets the...
Table Events of MultiScaleImage EventsDescription
ImageFailed Fires when the image cannot be downloaded or the image format is invalid. The event handler method is passed ExceptionRoutedEventArgs, which provides ErrorException the thrown Exception and ErrorMessage properties. ImageOpenFailed Fires when an image cannot be opened. ImageOpenSucceeded Fires when an image is successfully opened. MotionFinished Fires when the currently ongoing motion is complete. ViewportChanged Fires when the viewport the area of the image displayed changes. The...
NET Security in the CoreCLR
While application code executes under the auspices of an environment the CoreCLR executing on top of a host operating system, careful thought must still be given to how code is executed. In .NET, the security model for executable code is called Code Access Security CAS . There are several important aspects to CAS, including code making requests for specific security permissions such as asking for the ability to write to files , stack walks to determine the permission levels granted, and the...
LineGeometry
The LineGeometry class represents a single line with a start point and endpoint. Its two properties are shown in Table 7-1. Table 7-1. Properties of the System.WindowsMedia.LineGeometry Class Property Type Description StartPoint Point The x,y point of the start of the line EndPoint Point The x,y point of the end of the line Since the Geometry-based classes can't be shown directly, they must be shown using the Path class. Let's draw a line using the LineGeometry class in XAML lt Path Stroke Red...
Navigation Menu
Lorcm ipsum dolor sit amct, consectetuer adipiscing elit. Mauris dapibus sollicitudiii purus. Praesent laoreet Fusee id urna nee odio elementum placerat Quisque congue mollis tellus. Nulla facilisi. Fhasellus ultricies, nisi ut dictum tristique, tellus felis lacinia dui, vel adipiscing lectus tortor sit amet tellus. Sed metus. Figure 8-1. Design layout for a web site Two of these elements are visible in Figure 8-1 the section title and the page-specific text. Some other possible elements are...
ASP NET Silverlight Server Control
The Silverlight 3 SDK installed along with the Microsoft Silverlight Tools for Visual Studio 2008 SP1 includes the Silverlight server control to host Silverlight plug-ins. The following code snippet demonstrates this control, added in the SampleSilverlightNavigationRIATestPage. aspx file to host the SampleSilverlightNavigationRIA Silverlight application that will be developed in Chapter 14 form id form1 runat server style height 100 gt lt asp ScriptManager ID ScriptManager1 lt div style height...
Working with Shared Data
One of the trickiest problems when it comes to working with multiple threads is using shared resources typically, shared memory in the form of objects or primitive types. When it comes to shared data, one potential issue is known as a race condition. Figure 15-5 illustrates two threads attempting to increment a single integer variable named value. However, a simple increment is split into smaller operations behind the scenes the value of the variable is read, incremented, and stored back into...
An Example 1
Now it's time to create an example on how to use the Accordion control. The following are the prerequisites before you can utilize the Accordion control in your Silverlight project 1. Install the Silverlight Toolkit to your development machine as described in the section Silverlight Toolkit. 2. Add at least the Systems.Windows.Controls and Systems.Windows.Controls.Layout. Toolkit assemblies as references to your project. These assemblies are available on the .NET tab of the Add Reference...
Path
The Path class is by far the most versatile Shape-based class. This class can display any Geometry object by setting its Data property to the object. While this can be used to show complex Path-based geometries using PathGeometry, there is also a special syntax supported in XAML to specify Path-based geometries in a more terse string form. This syntax is utilized by Expression Media when constructing Path-based geometries. This syntax is used when specifying the value for the Data property of...
Creating a WCF Service Consumable by Silverlight
Let's write a simple web service that will be used by a Silverlight application. This web service will retrieve book-related information. First, create a Silverlight application project named chapter4, and add a BookInfo class under the web project. This class details the book profile and a list of chapters, as shown in the following code snippet public List lt string gt Chapters The service must use the basicHttpBinding as this is the only binding Silverlight can use. While you can create a...
Silverlight Child Window Template
Silverlight 3 introduces a new Silverlight Child Window template as part of the default installer. By introducing this template, Silverlight makes it easy for developers to implement modal windows in Silverlight-based RIAs. For example, you can use the Silverlight Child Window template to get the user's attention by providing a modal window and pausing the application flow for user interaction until the child window is closed. You can also use this feature as a popup window to display a...
Description Iwl
Nullable lt DateTime gt Nullable lt DateTime gt CalendarMode Contains a set of dates that are blacked out and thus cannot be selected by a user. Defines Style related to the control's internal CalendarButton object. Defines Style related to the control's internal CalendarItem object. Specifies the date to display in the calendar. Specifies the first date to display. Controls how the calendar presents itself. Possible values Month displays a full month at a time , Year displays a full year at a...
Using the RoleService
Once a user is authenticated and logged in, the RoleService is used to obtain the roles the user belongs to and to check whether he belongs to a specified role as part of the authorization process. Let's take a look at the methods the RoleService provides GetRolesForCurrentUser Returns an array of strings containing the roles the currently authenticated user belongs to IsCurrentUserlnRole Takes a role name and returns true if the user is a member of the role Once the user is authenticated and...
GridSplitter
The GridSplitter control, which is inherited from the Control class, is used to provide the user with the capability of changing sizes of rows and columns in a grid. It exposes three key properties, as described in Table 3-17. Table 3-17. Key Properties of the System.Windows.Controls.GridSplitter Class Table 3-17. Key Properties of the System.Windows.Controls.GridSplitter Class Gets sets whether the grid splitter responds to user interaction Gets sets the style used for previewing changes Gets...
RepeatButton
The functionality introduced by a RepeatButton is the repeated firing of the Click event for as long as the button is clicked. You can set several properties to control how the Click event fires Table 3-14 lists them. Table 3-14. Properties of the Class Table 3-14. Properties of the Class Number of milliseconds before the click action repeats, after the button is initially pressed. The default is 250. Number of milliseconds between repeated Click events, after repeating Here's the XAML for the...
Silverlight Service Utility Tool
The Silverlight Service Utility tool, SLsvcUtil.exe, is part of the Silverlight 3 SDK and can be found under C Program Files Microsoft SDKs Silverlight v3.0 Tools in a 32-bit environment in a 64-bit environment, the tool can be found under C Program Files x86 Microsoft SDKs Silverlight v3.0 Tools. This tool provides a large number of options. The default operation of the tool creates the client service configuration file ServiceReferences.ClientConfig and the necessary proxy code to contact the...
Using the DispatcherTimer
The DispatcherTimer works by hooking its Tick event up to a method that will be called on a periodic basis. You specify how often the Tick event is raised by passing a TimeSpan to the DispatcherTimer constructor or by setting the Interval property to the TimeSpan. The timer is then started via the Start method and stopped via the Stop method. Here's code that counts to 20 in 1-second intervals, displaying each number on the user interface private void startTimer_Click object sender,...
Arbitrary Linear Transforms
The final transformation class that Silverlight provides is the matrix transformation. This can be used when the other transformations don't give you what you want or when you want to combine multiple transformations into a single transformation although you could also use TransformGroup to group several . Each of the other transformations can be represented by a 3x3 matrix. Let's dust off our linear algebra textbooks and revisit the basics of matrix math to see how a matrix can give us the...
Silverlight Navigation Framework
Silverlight 2 did not support some basic web-based application features that would have been great additions to any RIA. Specifically, it did not support browsing from one XAML-based page to another, maintaining browser-level history, enabling the default browser's back and forward functionality, and implementing search engines. Although custom development made it possible to develop multiple-page RIAs in Silverlight 2, the implementation was pretty manual, and there were challenges when...
Style InheritanceStyle Cascading
Style inheritance, also known as style cascading or based-on styles, is one of the most widely used features in WPF-based applications. Most developers have used Cascading Style Sheets CSS when working with HTML pages, and style inheritance in Silverlight is the same. Having this feature incorporated in Silverlight 3 makes Silverlight application development more versatile. For example, say you need to create several different buttons that share the same control template and several style...
Bitmap Caching
Along with GPU hardware acceleration, Silverlight 3 introduces a new technique to improve the rendering performance of applications by caching vector content, text, and controls into bitmaps. Bitmap caching can be a useful and high-performing tactic in scenarios where content needs to scale without changes being made to its internal appearance. Bitmap caching is also an opt-in feature, and you need to explicitly enable it at the user interface element level. You can enable bitmap caching by...
Asynchronous Communication
The proxy supports two asynchronous mechanisms to invoke the service. The first, slightly easier, method is to provide a Completed event handler along with the operations of the service, followed by Async. The other method uses IAsyncResult with Begin End methods for each operation of the service. The key difference between these two is that the first approach is available directly on the client proxy and executes on the foreground thread, so it will block the user interface while contacting...
The Save File Dialog Box
The Save File dialog box is probably one of the most critical components and one of the most commonly used modal dialog boxes in desktop and web applications. Until Silverlight 2, Silverlight used only isolated storage as the primary area on the client machine for data storage. Silver-light 3 now supports a Save File dialog box to save data to the client's hard drive and is thus not limited to isolated storage. The SaveFileDialog class is derived from the System.Windows.Controls namespace....















