WPF - Tutorials Point

[Pages:44] WPF

About the Tutorial

WPF stands for Windows Presentation Foundation. It is a powerful framework for building Windows applications. This tutorial explains the features that you need to understand to build WPF applications and how it brings a fundamental change in Windows applications.

Audience

This tutorial has been designed for all those readers who want to learn WPF and to apply it instantaneously in different type of applications.

Prerequisites

Before proceeding with this tutorial, you should have a basic understanding of XML, Web Technologies and HTML.

Copyright & Disclaimer

? Copyright 2018 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at contact@

i

WPF

Table of Contents

About the Tutorial ..................................................................................................................................i Audience ................................................................................................................................................i Prerequisites ..........................................................................................................................................i Copyright & Disclaimer ...........................................................................................................................i Table of Contents ..................................................................................................................................ii

1. WPF ? OVERVIEW ..............................................................................................................1

WPF Architecture ..................................................................................................................................1 WPF ? Advantages.................................................................................................................................2 WPF ? Features......................................................................................................................................2

2. WPF ? ENVIRONMENT SETUP ............................................................................................ 3

Installation ............................................................................................................................................3

3. WPF ? HELLO WORLD ........................................................................................................7 4. WPF ? XAML OVERVIEW ..................................................................................................12

Basic Syntax.........................................................................................................................................12 Why XAML in WPF...............................................................................................................................13

5. WPF ? ELEMENTS TREE....................................................................................................17

Logical Tree Structure..........................................................................................................................17 Visual Tree Structure ...........................................................................................................................18

6. WPF ? DEPENDENCY PROPERTIES .................................................................................... 20

Why We Need Dependency Properties................................................................................................21 Custom Dependency Properties ..........................................................................................................22

7. WPF ? ROUTED EVENTS ...................................................................................................25

ii

WPF Direct Event.........................................................................................................................................25 Bubbling Event ....................................................................................................................................25 Tunnel Event .......................................................................................................................................25 Custom Routed Events ........................................................................................................................29

8. WPF ? CONTROLS ............................................................................................................34 9. BUTTON ........................................................................................................................... 37 10. CALENDAR ....................................................................................................................... 46 11. CHECKBOX ....................................................................................................................... 52 12. COMBOBOX ..................................................................................................................... 62 13. CONTEXTMENU ...............................................................................................................69 14. DATAGRID ........................................................................................................................ 76 15. DATEPICKER ..................................................................................................................... 85 16. DIALOG BOX.....................................................................................................................90 17. GRIDVIEW ........................................................................................................................ 93 18. IMAGE..............................................................................................................................99 19. LABEL ............................................................................................................................. 104 20. LISTBOX..........................................................................................................................108 21. MENU ............................................................................................................................ 113 22. PASSWORDBOX..............................................................................................................119 23. POPUP ........................................................................................................................... 123 24. PROGRESSBAR ............................................................................................................... 126

iii

WPF

25. RADIOBUTTON...............................................................................................................130 26. SCROLLVIEWER .............................................................................................................. 137 27. SLIDER............................................................................................................................143 28. TEXTBLOCK .................................................................................................................... 148 29. TOGGLEBUTTON ............................................................................................................ 151 30. TOOLTIP ......................................................................................................................... 155 31. WINDOW ....................................................................................................................... 158 32. THIRD-PARTY CONTROLS ............................................................................................... 162 33. WPF ? LAYOUTS ............................................................................................................. 169

Stack Panel ........................................................................................................................................169 Wrap Panel........................................................................................................................................172 Dock Panel.........................................................................................................................................175 Canvas Panel .....................................................................................................................................179 Grid Panel..........................................................................................................................................183

34. NESTING OF LAYOUT......................................................................................................187 35. WPF ? INPUT..................................................................................................................189

Mouse ...............................................................................................................................................189 Keyboard ..........................................................................................................................................193 ContextMenu or RoutedCommands ..................................................................................................195 Multi Touch .......................................................................................................................................198

36. WPF ? COMMAND LINE ................................................................................................. 203 37. WPF ? DATA BINDING .................................................................................................... 208

iv

WPF

One-Way Data Binding ......................................................................................................................208 Two-Way Data Binding ......................................................................................................................212

38. WPF ? RESOURCES.........................................................................................................215

Resource Scope .................................................................................................................................217 Resource Dictionaries ........................................................................................................................217

39. WPF ? TEMPLATES ......................................................................................................... 220

Control Template...............................................................................................................................220 Data Template...................................................................................................................................222

40. WPF ? STYLES.................................................................................................................227

Control Level .....................................................................................................................................231 Layout Level ......................................................................................................................................232 Window Level....................................................................................................................................234 Application Level ...............................................................................................................................235

41. WPF ? TRIGGERS............................................................................................................238

Property Triggers ...............................................................................................................................238 Data Triggers .....................................................................................................................................239 Event Triggers....................................................................................................................................241

42. WPF ? DEBUGGING........................................................................................................244

Debugging in C#.................................................................................................................................244 Debugging in XAML ...........................................................................................................................248 UI Debugging Tools for XAML ............................................................................................................251

43. WPF ? CUSTOM CONTROLS ........................................................................................... 254

User Control ......................................................................................................................................254 Custom Controls ................................................................................................................................258

v

WPF

44. WPF ? EXCEPTION HANDLING........................................................................................263

Syntax ...............................................................................................................................................263 Hierarchy ........................................................................................................................................... 264

45. WPF ? LOCALIZATION .................................................................................................... 270 46. WPF ? INTERACTION ...................................................................................................... 277

Behaviors ..........................................................................................................................................277 Drag and Drop ...................................................................................................................................280

47. WPF ? 2D GRAPHICS ...................................................................................................... 284

Shapes and Drawing ..........................................................................................................................284

48. WPF ? 3D GRAPHICS ...................................................................................................... 288 49. WPF ? MULTIMEDIA ...................................................................................................... 293

Speech Synthesizer............................................................................................................................295

vi

1. WPF ? OVERVIEW

WPF

WPF stands for Windows Presentation Foundation. It is a powerful framework for building Windows applications. This tutorial explains the features that you need to understand to build WPF applications and how it brings a fundamental change in Windows applications.

WPF was first introduces in .NET framework 3.0 version, and then so many other features were added in the subsequent .NET framework versions.

WPF Architecture

Before WPF, the other user interface frameworks offered by Microsoft such as MFC and Windows forms, were just wrappers around User32 and GDI32 DLLs, but WPF makes only minimal use of User32. So,

WPF is more than just a wrapper. It is a part of the .NET framework. It contains a mixture of managed and unmanaged code.

The major components of WPF architecture are as shown in the figure below. The most important code part of WPF are:

Presentation Framework Presentation Core Milcore

Presentation Framework

Presentation Core

CLR

User32

Milcore DirectX

Kernel

1

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download