1 / 26

An Introduction to Styles and Templates in Windows Presentation Foundation (WPF)

An Introduction to Styles and Templates in Windows Presentation Foundation (WPF). Adam Calderon – C# MVP Principal Engineer Interknowlogy. What We Will Cover. What Styles are and how to use them How Triggers can be used to replace common UI behavior

albert
Download Presentation

An Introduction to Styles and Templates in Windows Presentation Foundation (WPF)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An Introduction to Styles and Templates in Windows Presentation Foundation (WPF) Adam Calderon – C# MVP Principal Engineer Interknowlogy

  2. What We Will Cover • What Styles are and how to use them • How Triggers can be used to replace common UI behavior • How Templates can be used to skin controls • How all of this comes together

  3. Session Prerequisites • General Understanding of XML and XAML • Basic knowledge of Microsoft® Windows® Presentation Foundation (WPF) • Basic knowledge of WPF Resources Level 200

  4. Agenda • Styles • Triggers • Templates • Adding Style to an existing application

  5. StylesOverview of Styles • What are styles? • Problems they address • Elements that support styles

  6. StylesStyle Class Properties • Key • TargetType • Setters • Property • Event • Resources • Triggers

  7. Code Example of a Style <Style x:Key="Style1"> <Setter Property="Control.Background" Value="Yellow"/> </Style> <Label Content="Yellow Background" Style="{StaticResource Style1}" /> <Style TargetType="{x:Type TextBlock}"> <Setter Property="FontFamily" Value="Segoe Black" /> <Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="FontSize" Value="12pt" /> <Setter Property="Foreground" Value="#777777" /> </Style> <TextBlock>Some Text</TextBlock>

  8. StylesExtending Styles • Order of Precedence • BasedOn Property • Style-based • Element-based

  9. Demonstration One Styles in Action

  10. Agenda • Styles • Triggers • Templates • Adding Style to an existing application

  11. TriggersOverview of Triggers • Sets properties in response to end-user actions • No code solution to code-based remedies of today

  12. TriggersBasics of Triggers • Property set must be a dependency property • Properties reset when trigger dependent property changes back • Supports single trigger entries and multiple trigger entries (composite trigger) • Supports triggers that are dependent upon data binding and not just standard property binding

  13. Demonstration Two Triggers in Action

  14. Agenda • Styles • Triggers • Templates • Adding Style to an existing application

  15. TemplatesOverview of Templates • Defines visual appearance of controls • Out-of-box controls get their visual appearance from Templates • Brings together styles and triggers

  16. TemplatesBasics of Templates • Three types of templates: • ControlTemplate • ItemsPanelTemplate • DataTemplate • TemplateBinding links template and control properties • ContentPresenter can be used to display controls content

  17. Demonstration Three Templates in Action

  18. Agenda • Styles • Triggers • Templates • Adding Style to an existing application

  19. Adding Style to an ApplicationSteps • Use Style Setters to change the appearance of the text blocks • Use Control Templates to redefine the visual tree of a control • Use Data Templates to determine how the data appears • Use Triggers to create dynamic user interface (UI)

  20. Demonstration Four Transforming an Existing Application

  21. Session Summary • Styles are powerful and flexible • Triggers eliminate user interaction-based UI coding • Controls are more about behavior • Control Templates modify visual aspects of controls

  22. For More Information • MSDN® Links Microsoft Windows® Vista™ development center: http://msdn.microsoft.com/windowsvista/ Microsoft .NET Framework 3.0 for developers: http://msdn.microsoft.com/winfx/ Windows Presentation Foundation code-named "Avalon:” http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=119&SiteID=1 • Other Links Microsoft .NET Framework: http://www.netfx3.com/

  23. Additional Resources Applications = Code + Markup By Charles Petzold, Microsoft Press®

  24. Adam Calderon • More info on InterKnowlogy:www.InterKnowlogy.com • Contact Information E-mail: adamc@InterKnowlogy.com Phone: 760-930-0075 x274 Blog: http://blogs.InterKnowlogy.com/AdamCalderon • About Adam Calderon • Microsoft MVP – C# • Microsoft UI Server Frameworks Advisory Council • Developer / Author / Speaker

  25. Questions and Answers • Submit text questions using the “Ask” button. • Don’t forget to fill out the survey. • For upcoming and previously live webcasts: www.microsoft.com/webcasts • Got webcast content ideas? Contact us at: http://go.microsoft.com/fwlink/?LinkId=41781 • Today's webcast was presented using Microsoft® Office Live Meeting. Get a free 14-day trial by visiting: www.microsoft.com/presentlive

More Related