Module 4 Taking Control of the User Interface. Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using.

Slides:



Advertisements
Similar presentations
Module 1: Creating an Application by Using Windows Presentation Foundation Overview of WPF Creating a Simple WPF Application Handling Events and Commands.
Advertisements

Creating Windows Store Apps. 1. Overview of Windows Store applications 2. Worked example 3. Adding controls and event handlers Contents 2.
Introduction to Windows Presentation Foundation (WPF) Dr. Frank McCown COMP 445 – GUI Programming.
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
PowerPoint Chapter 2 Review
Dinko Jakovljević Microsoft Student Partner | BambooLab
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Customizing XAML Skins for PowerBuilder.NET WPF Applications
McGraw-Hill Career Education© 2008 by the McGraw-Hill Companies, Inc. All Rights Reserved. Office PowerPoint 2007 Lab 1 Creating a Presentation.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
Programming Based on Events
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Graphical User Interface (GUI) A GUI allows user to interact with a program visually. GUIs are built from GUI components. A GUI component is an object.
A Guide to Oracle9i1 Creating an Integrated Database Application Chapter 8.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Lesson 4: Formatting the Worksheet
© 2002 ComputerPREP, Inc. All rights reserved. Word 2000: Working with Long Documents.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
.NET Database Technologies: Introduction to WPF and Entity Framework DataBinding.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Module 11 Control Customization. Module Overview Overview of Control Authoring Creating Controls Managing Control Appearance by Using Visual States Integrating.
IE 411/511: Visual Programming for Industrial Applications
INSPIRING CREATIVE AND INNOVATIVE MINDS Module 4: Adding Code to a Microsoft ASP.NET Web Form Implementing Code-Behind Pages Adding Event Procedures to.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Assignment #1 Advanced Computer Programming.
Windows Presentation Foundation Adam Calderon Principal Engineer Interknowlogy LLC
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Basic WPF Controls Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer
V 1.0 Programming III. Automatic notifications (…Changed, INofityPropertyChanged, ObservableCollection ) Data formatters Data conversions Resources.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 7 – Adding and.
LAYOUT CONTROLS. XAML Overview XAML : eXtensible Application Markup Language pronounced (ZAMEL) is a markup language used to design user interfaces XML-based.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
Module 12 Attached Properties and Behaviors in WPF.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Unit 3: Adding Code to a Microsoft ASP.NET Web Form.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Presentation Foundation Ruwan Wijesinghe.
Adam Calderon – C# MVP Application Development Practice Lead Interknowlogy.
Module 2 Introduction to Visual Studio 2010 and WPF Version 4.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Module 7 Data Binding to Collections. Module Overview Binding to Collections of Objects Using Collection Views Create Master-Detail User Interfaces Using.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Windows Presentation Foundation (WPF). Introduction Separates appearance of user interface from behavior Appearance usually specified by XAML Behavior.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Module 13 Animations in WPF. Module Overview Using Animations Using Triggers Implementing Data Visualizations.
Module 14 Application Settings, State, and Life Cycle.
ControlTemplate and DataTemplate Doncho Minkov Telerik School Academy Technical Trainer
Module 3 Designing and Developing a User Interface.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
Module 8 Enhancing User Interface Responsiveness.
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
Word Create a basic TOC. Course contents Overview: table of contents basics Lesson 1: About tables of contents Lesson 2: Format your table of contents.
CPSC 481 – Week #7 Sowmya Somanath
Module 1 Introducing C# and the.NET Framework. Module Overview Introduction to the.NET Framework 4 Creating Projects Within Visual Studio 2010 Writing.
Model View ViewModel Architecture. MVVM Architecture components.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
24 Copyright © 2009, Oracle. All rights reserved. Building Views and Charts in Requests.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Presentation Foundation Ruwan Wijesinghe.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Part of the Microsoft.NET Framework 3.0 Tomer Shamam.NET Technologies Expert Sela Group
WaveMaker Visual AJAX Studio 4.0 Training Styling your application.
Adam Schultz MVVM and WPF. MVVM Model, View, ViewModel A software architecture designed to separate out User Interface design, Business Logic, and Data.
Dive Into® Visual Basic 2010 Express
Working in the Forms Developer Environment
Important New Concepts In WPF
MGB 2003 Adam Calderon – C# MVP Principal Engineer Interknowlogy
XAML User Interface Creation in C#
Web Development Using ASP .NET
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Brown Bag Seminar Summer 2007
Presentation transcript:

Module 4 Taking Control of the User Interface

Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using Styles Changing the Appearance of Controls by Using Templates Handling Events and Commands

Lesson 1: Sharing Logical Resources in an Application Understanding Resources Defining Resources Referencing Resources in XAML Referencing Resources Programmatically Reusing Resources Across Applications

Resources provide a simple way to reuse commonly defined objects and values Understanding Resources For example: brushes, styles, and control templates XAML Code

Defining Resources You can define resources at various levels: Application scope Window or Page scope Element-level scope Application scope Window or Page scope Element-level scope XAML

Referencing Resources in XAML To reference a resource statically: PropertyName="{StaticResource ResourceKey}" <Button Background="{StaticResource blueBrush}" Foreground="{StaticResource whiteBrush}"> Text <Button Background="{StaticResource blueBrush}" Foreground="{StaticResource whiteBrush}"> Text To reference a resource dynamically: PropertyName="{DynamicResource ResourceKey}" <Button Background="{DynamicResource blueBrush}" Foreground="{DynamicResource whiteBrush}"> Text <Button Background="{DynamicResource blueBrush}" Foreground="{DynamicResource whiteBrush}"> Text

Referencing Resources Programmatically FindResource method: SolidColorBrush brush = (SolidColorBrush) this.FindResource("whiteBrush"); SolidColorBrush brush = (SolidColorBrush) this.FindResource("whiteBrush"); SetResourceReference method: this.myButton.SetResourceReference( Button.BackgroundProperty, "whiteBrush"); this.myButton.SetResourceReference( Button.BackgroundProperty, "whiteBrush"); Resources property: SolidColorBrush brush = (SolidColorBrush) this.Resources["whiteBrush"]; SolidColorBrush brush = (SolidColorBrush) this.Resources["whiteBrush"]; Or TryFindResource

Reusing Resources Across Applications MyResources2.xaml Merged resource dictionaries: <ResourceDictionary Source="Resources\MyResources1.xaml" /> <ResourceDictionary Source="Resources\MyResources2.xaml" /> <ResourceDictionary Source="Resources\MyResources1.xaml" /> <ResourceDictionary Source="Resources\MyResources2.xaml" /> MyResources1.xaml Merged Resource Dictionary

Lesson 2: Creating Consistent User Interfaces by Using Styles Understanding Styles Defining Styles in XAML Extending Styles Setting Styles Programmatically

Understanding Styles You use styles to apply property values to elements: You typically define styles in Resources sections in XAML: You use styles to apply property values to elements: You typically define styles in Resources sections in XAML: Enable you to represent user interface properties such as font and background color as styles Enable you to represent user interface properties such as font and background color as styles Enable you to apply styles to multiple controls Promote consistent appearance of controls Enable you to apply styles to multiple controls Promote consistent appearance of controls Style Control

Defining Styles in XAML Style for all Label elements To define a style that sets properties for all elements of a specified type: Define a Style element 1 1 Set the TargetType property to an element type 2 2 Define Setter child elements to set property values 3 3

Extending Styles You extend a style by using the BasedOn property... <Style x:Key="headerText" BasedOn="{StaticResource myStyle}" TargetType="{x:Type Label}"> <Label Content="Title Text" Style="{StaticResource headerText}" /> <Label Content="Hello world" Style="{StaticResource myStyle}" />... <Style x:Key="headerText" BasedOn="{StaticResource myStyle}" TargetType="{x:Type Label}"> <Label Content="Title Text" Style="{StaticResource headerText}" /> <Label Content="Hello world" Style="{StaticResource myStyle}" /> headerText myStyle Title Text Hello world

Setting Styles Programmatically textblock1.Style = (Style)(Resources["TitleText"]); To apply a style programmatically: Index into the Resources collection 1 1 Cast the resource object into a Style instance 2 2 Set the Style property on the control 3 3 You can also modify styles programmatically to add, remove, or modify styles in the Resources collection

Lesson 3: Changing the Appearance of Controls by Using Templates Understanding Control Templates Defining a Template for a Content Control Defining a Template for an Items Control Applying Template Bindings Demonstration: Changing the Appearance of Controls by Using Control Templates

Understanding Control Templates Behavior class ControlTemplate Controls have built-in appearance and behavior: To customize the appearance and structure of a control: Controls have built-in appearance and behavior: To customize the appearance and structure of a control: The behavior is defined by a predefined control class The appearance is defined by a default ControlTemplate class The behavior is defined by a predefined control class The appearance is defined by a default ControlTemplate class Define a new ControlTemplate object for the control Control

Defining a Template for a Content Control To define a control template for a content control: 1.Define a Style element for a type of control 2.Set the Template property to a ControlTemplate object 3.Define a ContentPresenter element for the control content 1.Define a Style element for a type of control 2.Set the Template property to a ControlTemplate object 3.Define a ContentPresenter element for the control content <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Top"/>... <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Top"/>...

Defining a Template for an Items Control Identifies a panel as the container for the control’s items IsItemsHost Specifies the panel that the items control uses for the layout of items ItemsPanelTemplate Specifies the place in the control’s visual tree where the ItemsPanelTemplate element goes ItemsPresenter Horizontal ListBox

Applying Template Bindings You use a template binding to define properties in the control template: Enables the control template to use ambient property values <Border Background="{TemplateBinding ListBox.Background}" CornerRadius="5">... <Border Background="{TemplateBinding ListBox.Background}" CornerRadius="5">...

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 items controls by using control templates

Notes Page Over-flow Slide. Do Not Print Slide. See Notes pane.

Lesson 4: Handling Events and Commands Understanding Events in WPF Handling Events Understanding Routed Events Handling Routed Events Understanding Commands Defining Commands

Understanding Events in WPF WPF controls generate events such as: Clicking buttons Entering text Selecting lists Gaining focus

Handling Events Implement the event-handler method in the code-behind file Specify an event handler in the XAML file Click here Click here public void Button1_Click( object sender, RoutedEventArgs e) { MessageBox.Show("Hello WPF"); } public void Button1_Click( object sender, RoutedEventArgs e) { MessageBox.Show("Hello WPF"); }

Understanding Routed Events Root element Child element #1 Child element #2 Leaf element #1 Leaf element #2 Leaf element #2 WPF can route events up or down the element tree Event bubbling: Event routed up element tree Event bubbling: Event routed up element tree Event tunneling: Event routed down element tree Event tunneling: Event routed down element tree Tunnel Bubble Item clicked

Handling Routed Events Example of event bubbling Define leaf elements inside a container element Handle leaf events at the container level Yes No Yes No private void CommonClickHandler(object sender, RoutedEventArgs e) { var b = e.Source as Button;... } private void CommonClickHandler(object sender, RoutedEventArgs e) { var b = e.Source as Button;... }

Understanding Commands Commands separate the semantics of an action from its logic Multiple sources can trigger the same command You can customize the command logic for different targets Key concepts in WPF commanding: Commands Command sources Command targets Command bindings Examples of predefined commands: Copy, Cut, and Paste

Defining Commands Implement the event-handler method in the code-behind file Specify the CommandBindings element in the XAML file <CommandBinding Command=“Close” CanExecute=“OnCloseCanExecute” Executed=“OnCloseExecuted”/> <CommandBinding Command=“Close” CanExecute=“OnCloseCanExecute” Executed=“OnCloseExecuted”/> private void OnCloseCanExecute(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; } private void OnCloseExecuted(object sender, ExecutedRoutedEventArgs e) { this.Close(); } private void OnCloseCanExecute(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = true; } private void OnCloseExecuted(object sender, ExecutedRoutedEventArgs e) { this.Close(); }

Lab: Dynamically Controlling the User Interface Exercise 1: Creating Styles Exercise 2: Adding Application Commands Exercise 3: Adding Routed Events Exercise 4: Creating a Custom Command Exercise 5: Migrating a Custom Command Logon information Estimated time: 45 minutes

Notes Page Over-flow Slide. Do Not Print Slide. See Notes pane.

Lab Scenario You need to update the Work Orders application to meet the styling requirements of the application. You need to organize the inline styles into separate resource dictionaries. You must then provide the user with the ability to change the styles of the application while the application is running.

Lab Review Review Questions How do you merge multiple resource dictionary elements together? How do you migrate a RoutedUICommand class to fit with the MVVM design pattern?

Module Review and Takeaways Review Questions Best Practices