Sunteți pe pagina 1din 19

WPF WINDOWS PRESENTATION FOUNDATION

INTRODUCTION
The Windows Presentation Foundation is Microsofts next generation UI framework to create applications with a rich user experience. It is part of the .NET framework 3.0 and higher. WPF combines application UIs, 2D graphics, 3D graphics, documents and multimedia into one single framework. Its vector based rendering engine uses hardware acceleration of modern graphic cards. This makes the UI faster, scalable and resolution independent.

FEATURES
Declarative UI with XAML Multimedia support Skinning support .xps document 3D programming Highly compatible Animations and Timelines Powerful data bind Resolution independent Vector based rendering Hardware accelerator

SEPARATION OF APPEARANCE AND BEHAVIOUR


WPF separates the appearance of a user interface from its behaviour. The appearance is generally specified in theExtensible Application Markup Language (XAML) The behaviour is implemented in a managed programming language like C# or Visual Basic.

The two parts are tied together by data binding, events and commands

BENEFITS
The separation of appearance and behavior brings the following benefits. 1) Appearance and behavior are loosely coupled 2) Designers and developers can work on separate models.

3) Graphical design tools can work on simple XML documents instead of parsing code.

RICH COMPOSITION
Controls in WPF are extremely compassable. You can define almost any type of controls as content of another. Put an image into a button to create an image button, or put a list of videos into a combo box to choose a video file.

HIGHLY CUSTOMIZABLE
you can easily change the look of a control. The concept of styles let you skin controls almost like CSS in HTML. Templates let you replace the entire appearance of a control.

button button

a default WPF button

a customized button.

RESOLUTION INDEPENDENCE
All measures in WPF are logical units - not pixels. A logical unit is a 1/96 of an inch . If you increase the resolution of your screen, the user interface stays the same size - it just gets crispier. Since WPF builds on a vector based rendering engine it's incredibly easy to build scalable user interfaces .

XAML
Extensible Application Markup Language

INTRODUCTION
Language based on XML to create and initialize .NET

objects with hierarchical relations .


Although it was originally invented for WPF it can be used to create any kind of object trees . Today XAML is used to create user interfaces in WPF, Silver light, declare workflows in WF and for electronic paper in the XPS standard.

ADVANTAGES OF XAML
XAML code is short and clear to read. Separation of designer code and logic. Graphical design tools like Expression Blend require XAML as source. The separation of XAML and UI logic allows it to clearly separate the roles of designer and developer.

XAML VS. CODE


As an example we build a simple Stack Panel with a text block and a button in XAML and compare it to the same code in C #. //XAML <StackPanel> <TextBlock Margin="20">Welcome to the World of XAML</TextBlock> <Button Margin="10" HorizontalAlignment="Right">OK</Button> </StackPanel>

The same expressed in C# will look like this : // Create the StackPanel StackPanel stackPanel = new StackPanel(); this.Content = stackPanel; // Create the TextBlock TextBlock textBlock = new TextBlock(); textBlock.Margin = new Thickness(10); textBlock.Text = "Welcome to the World of XAML "; stackPanel.Children.Add (textBlock);

//Create the Button Button button = new Button (); button.Margin= new Thickness (20); button.Content = "OK"; stackPanel.Children.Add(button);

Thus the XAML version much shorter and clearer to read.

PROPERTIES AS ELEMENTS
Properties are normally written inline as known from XML <Button Content="OK" />. But what if we want to put a more complex object as content like an image that has properties itself or maybe a whole grid panel? . To do that we can use the property element syntax . This allows us to extract the property as an own child element . <Button> <Button.Content> <Image Source="Images/OK.png" Width=" 50 Height="50" /> </Button.Content> </Button>

IMPLICIT T YPE CONVERSION


A very powerful construct of WPF. They do their work silently in the background . When you declare a BorderBrush, the word "Blue" is only a string. The implicit Brush Converter makes a System.Windows.Media.Brushes.Blue out of it. The same regards to the BorderThickness that is being converted implicit into a Thickness object. WPF includes a lot of type converters for built -in classes, but you can also write type converters for your own classes . Eg. <Border BorderBrush="Blue" BorderThickness="0, 10"> </Border>

MARKUP EXTENSIONS
Dynamic placeholders for attribute values in XAML. They resolve the value of a property at runtime. Markup extensions are surrounded by curly braces (Eg: Background="{StaticResourceNormalBackgroundBrush }").

BUILT-IN MARKUP EXTENSIONS Binding -To bind the values of two properties together. Static Resource -One time lookup of a resource entry.

Dynamic Resource-Auto updating lookup of a resource entry.


Template Binding - To bind a property of a control template to a dependency property of the control x: Static-Resolve the value of a static property.

x:Null-Return null

NAMESPACES
At the beginning of every XAML file you need to include two namespaces. http://schemas.microsof t.com/winfx/2006/xaml/presentation . It is mapped to all wpf controls in System.Windows.Controls. http://schemas.microsof t.com/winfx/2006/xaml . It is mapped to System.Windows.Markup that defines the XAML keywords .

The mapping between an XML namespace and a CLR namespace is done by the XmlnsDefinition attribute at assembly level.
<Window xmlns =http://schemas.microsof t.com/ winfx/2006/xaml/presentati on xmlns:x =http://schemas.microsof t.com/ winfx/2006/xaml > </Window>

S-ar putea să vă placă și