The .NET 3 examples are (Note: Only IE is recommended for running these .NET 3.0 WPF examples):
Try: [Example 3] for the DotNet3 run from a Web browser. Note: Use IE!
Try: [Example 4] for the DotNet3 run from a Web browser. Note: Use IE!
Try: [Example 5] for the DotNet3 run from a Web browser. Note: Use IE!
Try: [Example 6] for the DotNet3 run from a Web browser. Note: Use IE!
Try: [Example 7] for the DotNet3 run from a Web browser. Note: Use IE!
Try: [Example 8] for the DotNet3 run from a Web browser. Note: Use IE!
Try: [Example 9] for the DotNet3 run from a Web browser. Note: Use IE!
Try: [Example 10] for the DotNet3 run from a Web browser. Note: Use IE!
Try: [Example 11] for the DotNet3 run from a Web browser. Note: Use IE!
Try: [Example 13] for the DotNet3 run from a Web browser. Note: Use IE!
Try: [Example 14] for the DotNet3 run from a Web browser. Note: Use IE!
A Introduction
1 . Start Visual Studio 2008, and select a WPF Application. Next add the following highlighted XAML code:
Try: [Example 1] for the DotNet3 run from a Web browser.
2 . Next try the following colours for the Border: AliceBlue, CornflowerBlue and MediumBlue.
3 . Next try to change the colour of the text on the button to AliceBlue.
4 . Change the name of the form to "Napier".
B Exporting and importing XAML
5 . Install Microsoft Expression Design (Figure 1), and start the package, and create the Scottish flag (see below). Once complete export it to c:\scotland.xaml.
Figure 1: Microsoft Expression Design
Note: if you cannot install with package on your computer, you can download the exported XML from:
9 . Next create a ListBox with the following highlighted text:
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Napier" Height="304" Width="466"> <Grid> <StackPanel> <TextBlock>My Menu</TextBlock> <ListBox> <ListBoxItem> Napier University </ListBoxItem> <ListBoxItem>Centre for Distributed Computing and Security</ListBoxItem> </ListBox> <RichTextBox/> </StackPanel> </Grid> </Window>
10 . Update the ListBox tags with the events:
<ListBoxItem Selected="Web1"> Napier University </ListBoxItem>
<ListBoxItem Selected="Web2"> Centre for Distributed Computing and Security </ListBoxItem>
17 . Create a new project with a Windows-based WPF application, and copy the code from the following. In this case it has the name of two of the text boxes (txtF and txtS):
19 . Figure 4 shows a sample run. Modify the XAML and C# code so that it shows the three other values in the message box.
Figure 4: Getting values
Try: [Example 5] for the DotNet3 run from a Web browser.
F Template standards
20 . In XAML it is possible to define new style tags. Add the highlighted code in the following example, and prove that it defines a new style. Update it so that it uses "Times New Roman" with non-bold text.
Try: [Example 6] for the DotNet3 run from a Web browser.
G StoryBoards
21 . In XAML it is possible to design a storyboard for animation. Enter the following highlighted code, and prove that when the button is pressed that the opacity goes from 100% to 0% in 5 seconds.
Try: [Example 7] for the DotNet3 run from a Web browser.
22 . Next update the code so that the button increases from 125 pixels to 300 pixels in 5 seconds (as shown next). Modify the code so that the height increases from 40 pixels to 80 pixels.
Try: [Example 8] for the DotNet3 run from a Web browser.
23 . The following allows for a colour change of a rectangle from Red to Blue, and back again (the source is at http://networksims.com/anim.zip). Run the program, and prove its operation. Change the colour from Black to White, over a period of 5 seconds.
Try: [Example 9] for the DotNet3 run from a Web browser.
24. Other events can be added, such as for the left hand mouse button click. Add the following code to the previous example (Ex 23), and prove its operation. Remeber to add it before the end Rectangle.Triggers tags.
25 . The following XAML code allows a red rectangle to be moved across the window (http://networksims.com/rect.zip). Check the program, and make sure that it left click mouse event on the rectangle causes it to animate, and a left click at the end will move it back to the start.
Try: [Example 10] for the DotNet3 run from a Web browser.
26 . XAML can contain key frames, where there are breakpoints in the animation. The following move a rectangle from 0 to 350 (for seven seconds), 350 to 50 (for five seconds) and 50 to 200 (in seconds seconds). Check the operation (http://networksims.com/rect2.zip), and then modify to that the same movement occurs in the x-direction (instead of the x-direction).
Try: [Example 11] for the DotNet3 run from a Web browser.
G Using Microsoft Expression Blend
27 . If you have Microsoft Expression Blend , create a new project. Next add a red rectangle on the screen, and then add a new timeline from the + button on the Object and Timeline (Figure 5). From the record line move on the 0 second mark, move the rectangle into the centre of the design area, then move to one second. Press the + button on the timeline (Record Keyframe). Then move to 1 second on the timeline, and move the rectangle to the left top-hand side, and press Record Keyframe. Finally move to the 2 second mark, and move the retangle, and press Record Keyframe. Finally go back to the 0 second keyframe, and change the fill colour to White. There should now be a blue dotted line for the path of the rectangle.
Figure 5: Adding a timeline in Blend
Figure 6: Showing timeline
28 . View the XAML (otherwise load it from ZIP), and integrate it with Visual Studio, and prove its operation.
Try: [Example 13] for the DotNet3 run from a Web browser.
29 . Finally, using Microsoft Expression Blend, draw the Union Jack Flag, and animate it so that it starts at the top-left hand side, moves to the top-right hand, then moves to the bottom right-hand side, and finally moves back to the original place. The flag should fade out when it reaches the top right-hand side.
Animating the rocket ship for a Web Page
In this example we will use Blend to create the XAML using a Web Page, and then import in Visual Studio. For this create a WPF Web Application, and add the XML given below.
Try: [Example 14] for the DotNet3 run from a Web browser. Note: Use IE!