VS 2008 and WPF
Posted by Rhonda Tipton on February 24, 2008
I finally got around to installing Visual Studio 2008 this weekend. The first thing I thought I would try to learn something about is Windows Presentation Foundation (WPF). WPF is a graphical subsystem feature of the .NET 3.0 framework that provides a clear separation between UI and Business logic. The mark up language used in WPF is called Extensible Application Markup Language (XAML). XAML looks like any other markup language like HTML and XML.
Below is a sample form built in WPF.
Create new project

Solution Explorer

XAML Designer
Form in Runtime

–
XAML Listing
<Window x:Class=”FirstWpf.Window1″ xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml” Title=”Calculate Max Heart Rate” Height=”181″ Width=”370″ Background=”LemonChiffon”> <Grid Height=”141″ Width=”339″> <Button Margin=”89,0,92,13″ Name=”button1″ Click=”button1_Click” Height=”23″ VerticalAlignment=”Bottom” FontWeight=”Bold” Foreground=”DarkGreen”>Click Me</Button> <TextBox Height=”23″ Margin=”0,21,115,0″ Name=”textAge” VerticalAlignment=”Top” HorizontalAlignment=”Right” Width=”36″ /> <Label Height=”23″ Margin=”83,21,0,0″ Name=”label1″ VerticalAlignment=”Top” HorizontalAlignment=”Left” Width=”65″ FontWeight=”Bold” Foreground=”DarkBlue”>Enter Age</Label> <Label Margin=”38,56,35,44″ Name=”labelHR” FontSize=”9″ ForceCursor=”False” HorizontalContentAlignment=”Center”></Label> </Grid> </Window>
C# Code Behind
using System; using System.Windows; namespace FirstWpf { public partial class Window1 : Window { public Window1() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { try { int age = Int32.MinValue; int maxHr = 0; age = Int32.Parse(textAge.Text); maxHr = 220 - age; labelHR.Content = “At the age of “ + age.ToString() + ” the Max HR should not rise above “ + maxHr.ToString(); } catch (Exception) { labelHR.Content = “Input is not valid”; return; } } } }
WPF/XAML is a feature rich and powerful programming model. In upcoming posts, I will go into deeper detail on some of the great features.
There are a plethora of internet resources for this interesting new technology. Below are just a few of them.
–
Related Content
Windows Client.NET - Official MS Site
Josh Smith on WPF
Karl on WPF
WPF Wonderland
The WPF Blog
Learn WPF
Your XAML Information Page
–
Happy programming!!!
Posted in Visual Studio, WPF | 3 Comments »




















