ControlTemplate and DataTemplate Doncho Minkov Telerik School Academy Technical Trainer

Slides:



Advertisements
Similar presentations
HTML Basics Customizing your site using the basics of HTML.
Advertisements

Panels, Tab Containers Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer
Introduction to HTML & CSS
Expression Blend 4 – deep dive
Project 8 Creating Style Sheets.
1 Lesson 5 Introduction to Cascading Style Sheets HTML and JavaScript BASICS, 4 th Edition Barksdale / Turner.
Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design.
Cascading Style Sheets Understanding styles. The term cascading describe the capability of a local style to override a general style. CSS applies style.
Chapter 3 Working with Text and Cascading Style Sheets.
Dinko Jakovljević Microsoft Student Partner | BambooLab
Windows Presetation Foundation (WPF) 1. Introduction.
Customizing XAML Skins for PowerBuilder.NET WPF Applications
Programming Based on Events
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Understanding HTML Style Sheets. What is a style?  A style is a rule that defines the appearance and position of text and graphics. It may define the.
© 2010 Delmar, Cengage Learning Chapter 7 Using Styles and Style Sheets for Design.
Chapter 3 Working with Text and Cascading Style Sheets.
Doncho Minkov Telerik School Academy academy.telerik.com Technical Trainer
© Ms. Masihi.  The Dreamweaver Welcome Screen first opens when you start Dreamweaver.  This screen gives you quick access to previously opened files,
Cascading Style Sheets. Defines the presentation of one or more web pages Similar to a template Can control the appearance of an entire web site giving.
Module 11 Control Customization. Module Overview Overview of Control Authoring Creating Controls Managing Control Appearance by Using Visual States Integrating.
Next Generation for Desktop Applications Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer
1 Intro XAML Attribute syntax & property syntax Panels Reusable resources Controls Data binding Steen Jensen, spring 2014.
V 1.1 Programming III. GUI APIs WPF Hello World Important UI elements UI elements / content models UI elements / inheritance.
Windows Presentation Foundation. Agenda Introduction Developing Applications WPF and WF interoperability Custom Controls Styles and Templates Data Binding.
Intro to Dreamweaver Web Design Section 7-1 Part or all of this lesson was adapted from the University of Washington’s “Web Design & Development I” Course.
Basic WPF Controls Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer
Data binding concepts, Bindings in WinJS George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
V 1.0 Programming III. Automatic notifications (…Changed, INofityPropertyChanged, ObservableCollection ) Data formatters Data conversions Resources.
LAYOUT CONTROLS. XAML Overview XAML : eXtensible Application Markup Language pronounced (ZAMEL) is a markup language used to design user interfaces XML-based.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Presentation Foundation Ruwan Wijesinghe.
Adam Calderon – C# MVP Application Development Practice Lead Interknowlogy.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Svetlin Nakov Telerik Corporation
Discover, Master, Influence1 Windows Presentation Foundation David Burela Senior Developer, Readify.
CSS BEST PRACTICES.
Introducing Cascading Style Sheets. Cascading Style Sheet Basics  Cascading Style Sheet Basics  Creating Styles  Using Styles  Manipulating Styles.
TRAINING SESSIONS.NET Controls.  Standard Controls  Label  Textbox  Checkbox  Button, Image Button, Image control  Radio Button  Literal  Hyperlink.
Reference: “ASP.NET 2.0 Illustrated” by Alex Homer and Dave Sussman. -ch3 illustrated book
Rujchai Ung-arunyawee Department of Computer Engineering Khon Kaen University.
LEARN THE QUICK AND EASY WAY! VISUAL QUICKSTART GUIDE HTML and CSS 8th Edition Chapter 8: Working with Style Sheets.
Cascading Style Sheets CSS. Source W3Schools
DYNAMIC HTML What is Dynamic HTML: HTML code that allow you to change/ specify the style of your web pages. Example: specify style sheet, object model.
Module 3 Designing and Developing a User Interface.
Module 4 Taking Control of the User Interface. Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using.
Windows Presentation Foundation ("Avalon"): Beautiful Code, Beautiful Design - Applications Your Designers Can Work With Robert Ingebretsen PRS317 Program.
.NET Framework Presentation. About Me Patrik Löwendahl –C# MVP –Certified Vista Touchdown Trainer Cornerstone
Microsoft Expression Web 3 – Illustrated Unit D: Structuring and Styling Text.
V 1.0 Programming III. Automatic notifications with data binding (…Changed, INofityPropertyChanged, ObservableCollection, DataTemplate) Data formatters.
Understand Databound Controls Windows Development Fundamentals LESSON 4.2A.
V 1.0 Programming III. XAML Data Binding I.. V 1.0ÓE-NIK, 2014 XAML namespaces Namespaces define the allowed tags and attributes The one without the prefix.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Presentation Foundation Ruwan Wijesinghe.
Part of the Microsoft.NET Framework 3.0 Tomer Shamam.NET Technologies Expert Sela Group
Data Binding, Binding Properties Doncho Minkov Telerik School Academy Technical Trainer
WPF Course Program, Evaluation, Exams Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
Jim Fawcett, Brown Bag Seminar Series Fall 2007
In Windows 8 Store Applications
Intro to Dreamweaver Web Design Section 8-1
Jim Fawcett, Brown Bag Seminar Series Fall 2007
ASP.NET Web Controls.
MGB 2003 Adam Calderon – C# MVP Principal Engineer Interknowlogy
Jim Fawcett CSE775 – Distributed Objects Spring 2011
XAML User Interface Creation in C#
CSS BEST PRACTICES.
The Web Wizard’s Guide To DHTML and CSS
WPF AKEEL AHMED.
.NET and .NET Core 7. XAML Pan Wuming 2017.
An introduction to MVVM using WPF NISCHAL S
Working with Text and Cascading Style Sheets
Web Development Using ASP .NET
Presentation transcript:

ControlTemplate and DataTemplate Doncho Minkov Telerik School Academy Technical Trainer

 Templating in WPF  Control Template  Data Templating  Styling  Triggers  Resource Dictionaries

 Two kinds of templates in WPF  ControlTemplate and DataTemplate  ControlTemplate is used for the visualization of the control itself  DataTemplate is used to present the content of the control

How to Control the Appearance?

 Controls in WPF are separated into:  Logic  Defines the states, events and properties  Template  Defines the visual appearance of the control  The wireup between the logic and the template is done by DataBinding

 Each control has a default template  This gives the control a basic appearance  The default template is typically shipped together with the control and available for all common windows themes  It is by convention wrapped into a style  Identified by value of the DefaultStyleKey property that every control has

 The template is defined by a dependency property called Template  The appearance of a control can be completely replaced by setting this to another instance  The ControlTemplate is often included in a style that contains other property settings

 ContentPresenter presents the Content of the Control <ControlTemplate TargetType="Button" x:Key="EllipseButton"> x:Key="EllipseButton"> <ContentPresenter HorizontalAlignment="Center" <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> VerticalAlignment="Center"/> </ControlTemplate>… <Button Content="Click" Template="{StaticResource EllipseButton}" /> Template="{StaticResource EllipseButton}" />

Live Demo

 DataTemplates are a similar concept as ControlTemplate  Give you a very flexible and powerful way to replace the visual appearance of a data item  Controls like ListBox, ComboBox or ListView  If you don't specify a data template  WPF takes the default template that is just a TextBlock

 If you bind complex objects to the control, it just calls ToString() on it  Within a DataTemplate, the DataContext is set to the data object  So you can easily bind to the data context to display various members of your data object

 Without a DataTemplate you just see the result of calling ToString() on the object.  With the data template we see the name of the property and a TextBox that even allows us to edit the value <DataTemplate> </DataTemplate>

Live Demo

Lets Make it Shiny!

 Style is a collection of property values that you can apply to an element in one step  Very similar to CSS standard in HTML  WPF styles allow you to define a common set of formatting characteristics  WPF styles limitations  You can't share styles between different elements  Each element can inherit just one Style  At least you can't do it the standard way

 Defining a Style for a Button Control  Inline in the  Inline in the    External Style file 18 </Button>

 Make a Button Control and set the Style Property  Style can be defined in Window.Resources : 19 <Button Style="{StaticResource BigButtonStyle}" x:Name="BigButtonExample" Content = "This is BIG!" /> <Window.Resources> </Window.Resources> Key property The target control The property we are overriding The new value

 There are 2 ways to customize a control  For example: CircledButton  Using Styles  Using Templates  In both you have to override the ControlTemplate  May lose some of the functionality of the control 20

21 … <Ellipse Stroke="Black" <Ellipse Stroke="Black" StrokeThickness="5" Fill="Blue"/> StrokeThickness="5" Fill="Blue"/> <TextBlock Foreground="Silver" <TextBlock Foreground="Silver" Background="Transparent" Text="With Style"/> Background="Transparent" Text="With Style"/> </Style>

Live Demo 22

Dynamic Styles

 Triggers define a list of setters that are executed if the specified condition is fulfilled  Property Triggers  When a property gets a specified value  Event Triggers  When a specified event is fired  Data Triggers  When a binding expression reaches a specified value 24

25 <ControlTemplate> <Ellipse x:Name="Circle" <Ellipse x:Name="Circle" Width="20" Height="20" Width="20" Height="20" Fill="Blue"/> Fill="Blue"/> <Trigger Property="IsMouseOver" <Trigger Property="IsMouseOver" Value="True"> Value="True"> <Setter TargetName="Circle" <Setter TargetName="Circle" Property="Fill" Value="Red"/> Property="Fill" Value="Red"/> </Controltemplate> The Property of the affected element Which element the trigger will affect When to execute the trigger

Live Demo

External Resources

 To avoid the length of code in one place, a ResourceDictionary can be used  Similar to the CSS external style files  Add new ResourceDictionary to your Project and put the Style / Template code inside  To access the Styles, Templates inside the ResourceDictionary : 28 <Window.Resources> <ResourceDictionary Source= <ResourceDictionary Source= "Resources\CircledButtonDictionary.xaml"/> "Resources\CircledButtonDictionary.xaml"/> </Window.Resources>

Live Demo

Questions?