Professional Documents
Culture Documents
Objectives
Introduce Windows Presentation Foundation (WPF) Investigate XAML and the XAML designer in Visual Studio 2010 Learn about XAML controls, properties, and events Work with container controls, dependency properties, and the Grid control
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
Agenda
Introducing Windows Presentation Foundation (WPF) Introducing XAML and the WPF Designer Investigating XAML Introducing Content and Grid Controls
Could create movie-style interfaces, but its difficult, and each requires its own set of tools
3D graphics extremely difficult without external libraries Standard Windows GDI and USER libraries extremely limited
experience
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
Ease of deployment
Allowing administrators to deploy and manage
applications securely
perhaps a better choice Can combine WPF and DirectX in the same application
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
JavaScript
Perfect for rich browser-based applications
Family.Show
Available for download at http://www.codeplex.com/familyshow Includes full source code and documentation on its design Includes family tree (truncated) for British royal family Can easily create your own family tree Provides rich visual representation, difficult to create without WPF Investigate zooming and panning features Different views of information
preferred deployment
WPF, too, is a set of classes Must write code to generate the interface Can either write code, or can write XAML Some names in XAML dont match the same member names in WPF classes
For Windows Forms application For WPF XAML <-> WPF is not one-to-one mapping
Agenda
Introducing WPF Introducing XAML and the WPF Designer Investigating XAML Introducing Content and Grid Controls
Properties of RoutedEventArgs
Handled OriginalSource RoutedEvent Source
Agenda
Introducing Windows Presentation Foundation (WPF) Introducing XAML and the WPF Designer Investigating XAML Introducing Content and Grid Controls
Investigating XAML
XAML is simple
But provides several different ways to set property
values
Investigating XAML
DEMO
Type Converters
Height and Width properties?
Properties are numeric Markup supplies values as strings Along the line, some code must convert Works because Integer class provides built-in conversion
from string
Type Converters
Margin adds own set of issues
Can supply a single value (all four sides) Can supply two values (left/right and top/bottom) Can supply four values (left, top, right, bottom)
Complex Properties
Type converters work well
Some properties cant be represented by single value
Properties of elements that are themselves objects with properties require special care
Represent as nested elements
DEMO
Complex properties
Markup Extensions
Usually, standard XAML markup provides functionality you need Sometimes not possible to set property value at design time
Some properties must be set dynamically, at runtime Need to use markup extension Allows you to set property in non-standard way
Markup Extensions
Declarative binding requires markup extension:
Property= "{Binding ElementName=ObjectName, Path=PropertyName}"
DEMO
Markup extension/binding
Attached Properties
Nest a control within a Grid
Specify its row and column with Grid.Row and
Attached Properties
Specific syntax:
DefiningType.PropertyName Grid.Row Aren't actually properties Converted to method calls by compiler Defining class must provide GetPropertyName and
SetPropertyName methods
Attached Properties
Of course, Grid doesn't keep track of all its children's coordinates Child controls all inherit from DependencyObject
Defined to maintain an unlimited number of dependency
properties
Attached Properties
Calling parent control's GetPropertyName and SetPropertyName methods equivalent to calling GetValue and SetValue methods of child object To retrieve Grid.Row property of TextBox named DemoTextBox, use expression like:
DemoTextBox.GetValue(Grid.RowProperty)
Agenda
Introducing WPF Introducing XAML and the WPF Designer Investigating XAML Introducing Content and Grid Controls
StackPanel
Stacks children horizontally or vertically Useful internal to other controls (Button, for example)
Canvas
No layout logic
Dependency Properties
In standard .NET code, property is defined using two procedures
setter and getter
Animation
Change notification and more
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
DependencyObject Class
DependencyProperty class acts as base for the properties DependencyObject is base for classes that can consume and expose dependency properties XAML classes expose far more properties than the corresponding prior classes
Need some internal plumbing to handle
Investigating DependencyProperty
.NET maintains internal dictionary of classes and the properties they expose DependencyProperty instance defined as a static/shared member of a class In constructor, code registers property, its type, and hosting class with .NET Can optionally create standard .NET property that wraps up the dependency property
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
In Constructor
[Visual Basic] MyClass.IsAvailableProperty = _ DependencyProperty.Register("IsAvailable", _ GetType(Boolean), GetType(MyClass)) [C#] MyClass.IsAvailableProperty = DependencyProperty.Register("IsAvailable", typeof(bool), typeof(MyClass))
Property Wrapper
[Visual Basic] Public Property IsAvailable() As Boolean Get Return _ CType(GetValue(MyClass.IsAvailableProperty), Boolean) End Get Set(ByVal value As Boolean) SetValue(MyClass.IsAvailableProperty, value) End Set End Property
Property Wrapper
[C#] public bool IsAvailable { get { return (bool) GetValue(MyClass.IsAvailableProperty); } set { SetValue(MyClass.IsAvailableProperty, value) } }
Learn More!
This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details!