Module 11 Control Customization. Module Overview Overview of Control Authoring Creating Controls Managing Control Appearance by Using Visual States Integrating.

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

Integrated Business Applications with Databases (D3) Jenny Pedler
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Module 10 WPF 2-D Graphics, Multimedia, and Printing.
Managing User Settings with Group Policy
Scenario Fixed look with some logic Split large page into smaller chunks Reuse xaml/logic in multiple places Platform Support … … public partial.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Copyright 2007, Paradigm Publishing Inc. POWERPOINT 2007 CHAPTER 1 BACKNEXTEND 1-1 LINKS TO OBJECTIVES Create Presentation Open, Save, Run, Print, Close,Delete.
Microsoft SharePoint 2013 SharePoint 2013 as a Developer Platform
Managing Client Access
Module 4 Managing Client Access. Module Overview Configuring the Client Access Server Role Configuring Client Access Services for Outlook Clients Configuring.
Module 2 Creating Active Directory ® Domain Services User and Computer Objects.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Module 13: Configuring Availability of Network Resources and Content.
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 14: Configuring Print Resources and Printing Pools.
An Introduction to Silverlight Matt Harrington Developer Evangelist, Microsoft October 20, 2011.
Windows Presentation Foundation. Agenda Introduction Developing Applications WPF and WF interoperability Custom Controls Styles and Templates Data Binding.
Chapter 8: Writing Graphical User Interfaces
Virtual techdays INDIA │ Nov 2010 Developing Office Biz Application using WPF on Windows 7 Sarang Datye │ Sr. Consultant, Microsoft Sridhar Poduri.
INSPIRING CREATIVE AND INNOVATIVE MINDS Module 4: Adding Code to a Microsoft ASP.NET Web Form Implementing Code-Behind Pages Adding Event Procedures to.
Windows Presentation Foundation Adam Calderon Principal Engineer Interknowlogy LLC
Module 9 Configuring Messaging Policy and Compliance.
Module 9 Authenticating and Authorizing Users. Module Overview Authenticating Connections to SQL Server Authorizing Logins to Access Databases Authorization.
Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.
Module 9 Configuring Messaging Policy and Compliance.
Module 12 Attached Properties and Behaviors in WPF.
1 ADVANCED MICROSOFT WORD Lesson 14 – Editing in Workgroups Microsoft Office 2003: Advanced.
Module 6 Securing Content. Module Overview Administering SharePoint Groups Implementing SharePoint Roles and Role Assignments Securing and Auditing SharePoint.
Module 3 Configuring File Access and Printers on Windows 7 Clients.
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.
CMPF124 Basic Skills For Knowledge Workers Module 3 Microsoft Office Suite Pt 3 Microsoft PowerPoint Microsoft Office Suite Pt 3 Microsoft PowerPoint.
Module 1 Windows Client Application Design. Module Overview Windows Client Technologies Architectural Patterns.
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.
A Lap Around Windows Presentation Foundation. Why hasn’t UX taken off in software? It’s Difficult! Animation 2D 3D Documents Styled Controls Video Windows.
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.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
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.
Module 8 Enhancing User Interface Responsiveness.
Microsoft ® Official Course Developing a Publishing Site for Web Content Microsoft SharePoint 2013 SharePoint Practice.
Module 4: Creating a Web Application with Web Forms
1 Catching up on Rich Clients (round 1) Mike Ormond, Mike Taulty Developer & Platform Group Microsoft Ltd
Module 4 Taking Control of the User Interface. Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using.
ASP.NET User Controls. User Controls In addition to using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls.
Module 12: Configuring and Managing Storage Technologies
Windows Presentation Foundation ("Avalon"): Beautiful Code, Beautiful Design - Applications Your Designers Can Work With Robert Ingebretsen PRS317 Program.
Friday, March 8 Creating real Custom Controls Kelvin van Geene 12:15.
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.
Building Custom Controls with ASP.NET and the Microsoft ®.NET Framework Rames Gantanant Microsoft Regional Director, Thailand
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
Working in the Forms Developer Environment
Important New Concepts In WPF
MIX 09 9/12/2018 8:06 AM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Jim Fawcett CSE775 – Distributed Objects Spring 2011
XAML User Interface Creation in C#
Understand Windows Forms Applications and Console-based Applications
WPF AKEEL AHMED.
.NET and .NET Core 7. XAML Pan Wuming 2017.
XAML Deep Dive for Windows & Windows Phone Apps Jump Start
Web Development Using ASP .NET
Brown Bag Seminar Summer 2007
Presentation transcript:

Module 11 Control Customization

Module Overview Overview of Control Authoring Creating Controls Managing Control Appearance by Using Visual States Integrating WPF and Windows Forms Technologies

Lesson 1: Overview of Control Authoring Why Create New Controls? Options for Creating New Controls Implementing User Controls Implementing Custom Controls Deriving from the FrameworkElement Class

Why Create New Controls? WPF provides many features that reduce the need to create new controls: Rich content Styles Control templates Triggers Data templates

Options for Creating New Controls FrameworkElementControlUserControl WPF provides three control-authoring models: Deriving from the UserControl class Deriving from the Control class Deriving from the FrameworkElement class

Implementing User Controls To create a user control: Define a UserControl element by using XAML Define a class that inherits from the UserControl class Use styles and triggers if required You may want to create a user control when: You want to build a control in a similar manner to how you build an application Your control consists only of existing components You do not need to support complex customization

Implementing Custom Controls To create a custom control: Define a class that inherits from the Control class Define a ControlTemplate element Use themes if required You may want to create a custom control when: You want to enable customization of your control by using control templates You want your control to support various themes

Deriving from the FrameworkElement Class There are two method to create a control that derives from the FrameworkElement class: Direct rendering Custom element composition You may want to create a FrameworkElement-derived control when: You want precise control over appearance You want to use your own rendering logic You want to use custom element composition

Lesson 2: Creating Controls Creating a User Control Implementing Properties and Events Creating a Custom Control Implementing Commands Enhancing Controls by Using Themes Demonstration: Implementing a NumericUpDown Control

Creating a User Control To create a user control: 1.Create a UserControl XAML element 2.Add layout elements and standard controls 3.Implement a class that inherits from the UserControl class Up Up namespace MyNamespace { public class NumericUpDown : UserControl {... namespace MyNamespace { public class NumericUpDown : UserControl {...

Implementing Properties and Events To define properties and events for a user control: public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value",...); public decimal Value { get { return (decimal)GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } } public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value",...); public decimal Value { get { return (decimal)GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } } public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent("ValueChanged",...); public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent("ValueChanged",...); Define properties as dependency properties Define events as routed events

Creating a Custom Control To define a custom control: namespace MyNamespace { public class NumericUpDown : Control {...}... namespace MyNamespace { public class NumericUpDown : Control {...}... <Application xmlns:local="clr-namespace:MyNamespace"...>... <ControlTemplate TargetType="{x:Type local:NumericUpDown}">... <Application xmlns:local="clr-namespace:MyNamespace"...>... <ControlTemplate TargetType="{x:Type local:NumericUpDown}">... Create a class that inherits from the Control class Define the appearance by using a Style element

Implementing Commands You implement commands in custom controls to decouple the event handling for the control public class NumericUpDown : Control { public static RoutedCommand IncreaseCommand; public static RoutedCommand DecreaseCommand;... public class NumericUpDown : Control { public static RoutedCommand IncreaseCommand; public static RoutedCommand DecreaseCommand;... <RepeatButton Command="{x:Static local:NumericUpDown.IncreaseCommand}"...>Up <RepeatButton Command="{x:Static local:NumericUpDown.DecreaseCommand}"...>Down <RepeatButton Command="{x:Static local:NumericUpDown.IncreaseCommand}"...>Up <RepeatButton Command="{x:Static local:NumericUpDown.DecreaseCommand}"...>Down Defined in the template of a Style element

Enhancing Controls by Using Themes To create a theme file: [assembly: ThemeInfo( ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] [assembly: ThemeInfo( ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] 1.Create a folder named themes 2.Create generic.xaml in the themes folder 3.Define a ResourceDictionary with the Style element 4.Specify the theme location in the hosting application Defined in generic.xaml In the hosting application

Demonstration: Implementing a NumericUpDown Control In this demonstration, you will see how to: View the code for a user control implementation of the NumericUpDown control View the code for a custom control implementation of the NumericUpDown control

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

Lesson 3: Managing Control Appearance by Using Visual States Understanding the VisualStateManager Class Implementing Visual States for Controls Changing the Current Visual State Demonstration: Implementing Visual States by Using the VisualStateManager Class

Understanding the VisualStateManager Class VisualStateManager.VisualStateGroups VisualStateGroup VisualState VisualStateGroup.Transitions VisualState VisualTransition Control Code: Contains a Storyboard element [TemplateVisualState( Name = "Normal", GroupName = "CommonStates")] [TemplateVisualState( Name = "Normal", GroupName = "CommonStates")]

Implementing Visual States for Controls <ColorAnimation To="Green" Storyboard.TargetName="rectBrush" Storyboard.TargetProperty="Color"/> <VisualTransition To="Normal" GeneratedDuration="00:00:00"/> <VisualTransition To="MouseOver" GeneratedDuration="00:00:00.5"> <ColorAnimation To="Green" Storyboard.TargetName="rectBrush" Storyboard.TargetProperty="Color"/> <VisualTransition To="Normal" GeneratedDuration="00:00:00"/> <VisualTransition To="MouseOver" GeneratedDuration="00:00:00.5">

Changing the Current Visual State Control Code: VisualStateManager.GoToState(this, "MouseOver", true); Type of restrictionFrom propertyTo property From a specified state to another specified state Visual state name From any state to a specified stateNot set Visual state name From a specified state to any state Visual state name Not set From any state to any stateNot set Default transition

Demonstration: Implementing Visual States by Using the VisualStateManager Class In this demonstration, you will see how to: Open the existing application View the control template View the visual states View the visual state transitions View the NumericUpDown control code Run the application

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

Lesson 4: Integrating WPF and Windows Forms Technologies Understanding WPF and Windows Forms Integration Hosting Windows Forms Controls in a WPF Application Hosting WPF Controls in a Windows Forms Application

Understanding WPF and Windows Forms Integration Windows Forms integration: Reuse existing investment in Windows Forms code Some Windows Forms controls have no WPF equivalent WPF integration: Enhance existing investment in Windows Forms code Enables iterative approach to migration to WPF

Hosting Windows Forms Controls in a WPF Application WindowsFormsHost element WindowsFormsHost element System.Windows.Forms and WindowsFormsIntegration assemblies System.Windows.Forms and WindowsFormsIntegration assemblies Child property Cast to relevant type Attach event handlers Manipulate properties Child property Cast to relevant type Attach event handlers Manipulate properties (this.wfh.Child as MaskedTextBox).ValueChanged += new EventHandler(this.MaskedTextBox_ValueChanged); (this.wfh.Child as MaskedTextBox).ValueChanged += new EventHandler(this.MaskedTextBox_ValueChanged);

Hosting WPF Controls in a Windows Forms Application private void MyForm_Load(object sender, EventArgs e) { elemHost = new ElementHost();... System.Windows.Controls.Button wpfButton = new System.Windows.Controls.Button(); wpfButton.Content = "Windows Presentation Foundation Button"; elemHost.Child = wpfButton; // Map the Margin property. this.AddMarginMapping(); // Remove the mapping for the Cursor property. this.RemoveCursorMapping(); // Cause the OnMarginChange delegate to be called. elemHost.Margin = new Padding(23, 23, 23, 23); } private void MyForm_Load(object sender, EventArgs e) { elemHost = new ElementHost();... System.Windows.Controls.Button wpfButton = new System.Windows.Controls.Button(); wpfButton.Content = "Windows Presentation Foundation Button"; elemHost.Child = wpfButton; // Map the Margin property. this.AddMarginMapping(); // Remove the mapping for the Cursor property. this.RemoveCursorMapping(); // Cause the OnMarginChange delegate to be called. elemHost.Margin = new Padding(23, 23, 23, 23); } WindowsFormsIntegration assembly

Lab: Building a User Control Exercise 1: Choosing the Appropriate Control Type Exercise 2: Creating a WPF User Control Exercise 3: Adding a WPF Control to a Windows Forms Application Logon information Estimated time: 45 minutes

Lab Scenario You have been asked to turn your prototype graphic control into a control that the Product Inventory application will consume. The Product Inventory application is written by using Windows Forms, but you will use WPF to write the new control; therefore, you must also integrate the new control into the older application.

Lab Review Review Questions Which method do you use to create a dependency property? Which control do you use to host a WPF control in a Windows Forms application? Which property do you use to add or remove property mappings for a hosted control?

Module Review and Takeaways Review Questions Best Practices