4. Why WPF? Another UI Framework?
New Display Engine
Based on Direct3D no window handles
Leverages Modern Hardware (GPUs)
Resolution Independence
Vectorgraphics Scalable
Multimedia Integration
Controls + Documents + Video/Audio
New .NET based Development Concept
New class libraries
Seperated UI vs. Logic
XAML – XML based UI Specification language
7. XAML
Extensible Application Markup Language
Generic XML Object Instantiation
Not How – but What!
Creates Object Hierarchies
Used in
Windows Presentation Foundation
Windows Workflow Foundation
8. XAML vs. C#
<Button Background=quot;Redquot;>
Click Me!
</Button>
Button button1 = new Button();
button1.Content = quot;Click Me!quot;;
button1.Background = new SolidColorBrush(
Colors.Red);
9. XAML vs. C#
XML Namespaces <--> .NET Namespaces
XML Elements <--> .NET Objects
XML Attributes <--> .NET Object Properties
25. Dependency Properties
Values stored in a central dictionary
Instead of being stored in a private member
Can include additional metadata (like default value)
Manipulated by the WPF runtime
Databinding
Animation, Styles, etc…
26. Dependency Properties
public class MyDependencyObject : DependencyObject
{
public static readonly DependencyProperty
SomeStateProperty =
DependencyProperty.Register(quot;SomeStatequot;,
typeof(String), typeof(MyDependencyObject));
public string SomeState
{
get { return (string)this.GetValue(SomeStateProperty); }
set { this.SetValue(SomeStateProperty, value); }
}
}
27. Attached Properties
Store Properties of one control on another
one
<Grid>
<Button Grid.Column=“0quot; Grid.Row=quot;40quot;>
Click Me!
</Button>
</Grid>
37. Resource Hierarchy
<Window>
System Resources <Window.Resources>
...
</Window.Resources>
Application Application
Resources Resources <Grid>
<Grid.Resources>
...
Window/Page Window/Page
</Grid.Resources>
Resources Resources
<ListBox>
Element Element <ListBox.Resources>
Resources Resources ...
</ListBox.Resources>
</ListBox>
Element Element
</Grid>
Resources Resources
</Window>
38. Automatic Styles/Templates
Most resources must use x:Key
Optional with Styles and Data Templates
Can use TargetType or DataType instead
Applied to target automatically – no reference required
<Window.Resources>
<Style TargetType=quot;{x:Type TextBlock}quot;>
<Setter Property=quot;Marginquot; Value=quot;5quot; />
</Style>
</Window.Resources>
39. Lookless Controls and Templates
Control implies behaviour
Probably supplies default look
Designer free to supply new look
46. Provide Data From Code
May be easier to load data in codebehind
Can set DataContext in code
Foo myDataObject = new Foo();
myDataObject.Bar = 42;
// Set DataContext
myWindow.DataContext = myDataObject;
49. Data and Controls
ContentControl – singular content
Button, CheckBox, Label, ListBoxItem, …
ItemsControl – plural content
ListBox, ComboBox, Menu, TabControl, ToolBar, …
Can use data objects as content
myButton.Content = new Car();
myListBox.Items.Add(new Car());
Car c = (Car) myListBox.SelectedItem;
65. Interoperability!
Can use WPF with existing code
WPF inside existing code
Existing code inside WPF
Interop at the component level
Maximum richness => all WPF
66. Airspace
One pixel, one technology
File Edit View Help File Edit View Help
Win32 WPF Win32 WPF
DirectX DirectX
69. Mixed Application Ideas
A new look for your chrome
Visual effects for your canvas
WPF for faster rendering?
Wizards and help systems
Generate HTML => Generate XAML
70. Windows Forms
private void WindowLoaded(object sender, EventArgs e)
{
WindowsFormsHost host = new WindowsFormsHost();
host.Height = new Length(120);
host.Width = new Length(150);
swf.Control child = new UserControl1();
child.Dock = swf.DockStyle.None;
host.AddChild(child);
border.Child = host;
}