Professional Documents
Culture Documents
6460a 03
6460a 03
Windows® Presentation
Foundation
Module 3: Customizing Appearance
• Sharing Logical Resources in an Application
• Defining Resources
XAML
Code
Defining Resources
• Application scope
• Window or Page scope
• Element-level scope
XAML
<Window.Resources>
<SolidColorBrush x:Key="blueBrush" Color="Blue"/>
<SolidColorBrush x:Key="whiteBrush" Color="White"/>
<sys:Double x:Key="myValue">100</sys:Double>
</Window.Resources>
Referencing Resources in XAML
FindResource method:
Or TryFindResource
SetResourceReference method:
this.myButton.SetResourceReference(
Button.BackgroundProperty, "whiteBrush");
Resources property:
MyResources1.xaml MyResources2.xaml
Demonstration: Sharing Resources in a
WPF Application
In this demonstration, you will see how to:
• Define and reference resources by using XAML
• Automatic layout
• Localization attributes and comments
• Bidirectional content support
FlowDirection property
Number substitution
• Localized content in satellite assemblies
Lesson: Creating Consistent User Interfaces by
Using Styles
• What Are Styles?
• Defining Styles
• Extending Styles
Style Control
<Resources />
Defining Styles
<Page.Resources>
<Style x:Key="myStyle" TargetType="{x:Type Label}">
<Setter Property="Background" Value="Blue" />
<Setter Property="Foreground" Value="White" />
</Style>
</Page.Resources> Style for all Label
elements
Extending Styles
headerText
Title Text myStyle
Hello world
Setting Styles Programmatically
textblock1.Style = (Style)(Resources["TitleText"]);
Behavior class
Control
ControlTemplate
Defining a Control Template for a Content Control
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Ellipse Fill="Blue"/>
<ContentPresenter VerticalAlignment="Center"
HorizontalAlignment="Top"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Defining a Control Template for an Items Control
Horizontal ListBox
Providing User Customization by Using Template
Bindings
<Style TargetType="ListBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<Border Background="{TemplateBinding ListBox.Background}"
CornerRadius="5">
...
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Demonstration: Changing the Appearance of
Controls by Using Control Templates
In this demonstration, you will see how to:
• Modify the appearance of content controls by using control
templates
• Modify the appearance of a items controls by using control
templates
Lesson: Enhancing User Interfaces by Using
Triggers and Animations
• What Are Triggers?
• Defining Animations
Trigger types:
• EventTrigger • MultiTrigger
Types of animation:
• ColorAnimation
• DoubleAnimation
• PointAnimation
• Custom
Defining Animations
and Animations
Logon information
Password Pa$$w0rd
• Tools