Академический Документы
Профессиональный Документы
Культура Документы
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
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 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
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.
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);
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>
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.
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>