Click here to Skip to main content
Click here to Skip to main content

Step into the new Microsoft Windows Presentation Foundation (WPF)

, 16 Mar 2007
Rate this:
Please Sign up or sign in to vote.
Simple steps to start with the Windows Presentation Foundation

Introduction

The Microsoft Windows Presentation Foundation (WPF) formerly code named "Avalon" provides the foundation for building applications and high reliability experiences in Longhorn, blending together application UI, documents, and media content, while exploiting the full power of your computer. WPF is the graphical subsystem of .NET frameworks 3.0 formerly called WinFX. XAML is the markup language used to write WPF applications. WPF provides developers and designers with a unified programming model for building rich Windows smart client user experiences that incorporate UI, media, and documents. WPF provides a reliable programming model for building applications and provides a clear separation between the User Interface and the business logic.

XAML

Extensible Application Markup Language (XAML) by Microsoft is a declarative XML-based language used to define objects and their properties, relationships and interactions. The acronym originally stood for Extensible Avalon Markup Language, where Avalon was the code name for Windows Presentation Foundation (WPF), but now it stands for Extensible Application Markup Language. XAML files are XML files that generally have the .xaml extension.

XAML is used as a UI objects, events and many others in Windows Presentation Foundation. In Windows Workflow Foundation the Workflow is also defined using XAML. In addition, Visual Studio, SharePoint Designer, Microsoft Expression and XAMLpad are used for XAML file manipulation.

WPF Applications

Windows Presentation Foundation has many good features that enriches your next generation applications. WPF is intended to be the next-generation graphics API for Windows applications on the desktop. Applications written in WPF are visually of a higher quality. The features that enriched in WPF are Graphical Services, Deployment, Interoperability, Media Services, Data Binding, User Interface, Annotations, Imaging, Effects, Text, Input and Accessibility.

Start with a sample WPF web application

After setting your infrastructure for your WPF application development, first open you're your Visual Studio 2005 and create new project. This WPF project template will come under the .NET frameworks 3.0 and select the WinFX Web Browser Application project template. And your new project will be created with two .xaml files and other files associated with the project created.

Add a root Page element to Default.xaml, with custom configurations as per your needs. First the title bar of the browser is set to "My First WPF Application", and then width of the browser is 800 device-independent pixels, then height of the browser is 600 device-independent pixels, then title of the page is "My First WPF Application – Home Page".

If you find the following namespace under your Default.xaml file,
xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"

Then replace them with the following namespace.< br/> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Now add a new WinFX page and name it as DisplayPage.xaml. This DisplayPage.xaml file will finally be used to bind display data to the UI.

In the Default.xaml file add the following XAML tags to display a text with hyper linked. The hyperlink will navigate to your next XAML file.

<!--  Add Links to Other Pages Here -->
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" 
    Margin="0 0 0 40">
    <TextBlock>
        <Hyperlink NavigateUri="DisplayPage.xaml">
            Data DisplayPage
        </Hyperlink>
    </TextBlock>
</StackPanel>

In the above format the text will display in your browser. Then you can place the text anywhere in your browser by display formatting. The following XAML tag will help you to format the display of your text.

<!--  Basic Display Formatting Below Text-->
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.Resources>
    <Style TargetType="{x:Type TextBlock}">
        <Setter Property="FontFamily" Value="Lucida Console" />
        <Setter Property="FontSize" Value="30" />
    </Style>
</Grid.Resources>

Now add an image file to your solution and how it can be displayed. In this sample I'm trying to add an image called tiger.PNG. In the Solution Explorer tree, right-click the image and select Properties from the context menu.

Change the build action from Resource to Content.

And change the copy to output directory as copy always.

And place the following XAML tags in your DisplayPage.xaml file.

<Viewbox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" 
    StretchDirection="DownOnly">
    <Canvas Width="600" Height="600">
        <Canvas>
            <!-- bounding image Path -->
            <Image Source="tiger.PNG" />
        </Canvas>
    </Canvas>
</Viewbox>

These are the simple steps to start with the Windows Presentation Foundation. Hopefully this will help beginner of WPF.

Setup infrastructure for your application

"WPF/E" (codename) Community Technology Preview for Windows (Feb 2007)
"WPF/E" (codename) Community Technology Preview Sample Pack (Feb 2007)
WPF/E" (codename) Software Development Kit (SDK) Community Technology Preview (Feb 2007)

Others

Microsoft Expression Web Free Trial
Microsoft® Expression Web Quickstart Guide

References

http://wpf.netfx3.com/
http://msdn2.microsoft.com/en-us/netframework/aa663321.aspx< br/> http://www.xamldev.com

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

vivekthangaswamy
Software Developer
Australia Australia
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 16 Mar 2007
Article Copyright 2007 by vivekthangaswamy
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid