Mastering Windows Presentation Foundation Second Edition

Mastering Windows Presentation Foundation Second Edition

Mastering Windows Presentation Foundation Second Edition Build responsive UIs for desktop applications with WPF Sheridan Yuen BIRMINGHAM - MUMBAI Mastering Windows Presentation Foundation Second Edition Copyright © 2020 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author(s), nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Commissioning Editor: Kunal Chaudhari Acquisition Editor: Denim Pinto Content Development Editor: Rosal Colaco Senior Editor: Storm Mann Technical Editor: Pradeep Sahu Copy Editor: Safis Editing Project Coordinator: Francy Puthiry Proofreader: Safis Editing Indexer: Priyanka Dhadke Production Designer: Alishon Mendonsa First published: February 2017 Second edition: March 2020 Production reference: 1270320 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-83864-341-6 www.packt.com www.EBooksWorld.ir Packt.com Subscribe to our online digital library for full access to over 7,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website. Why subscribe? Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals Improve your learning with Skill Plans built especially for you Get a free eBook or video every month Fully searchable for easy access to vital information Copy and paste, print, and bookmark content Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. Contributors About the author Sheridan Yuen is a Microsoft .NET MCTS and Oracle Java SCJP certified software developer, living in London, England. His passion for coding made him stand out from the crowd right from the start. Since his second year at university, he was employed as a teaching assistant for the first year student coding workshops and has been returning as a guest lecturer. Among other prestigious positions, he was the primary software developer for the Ministry of Sound group for four years, working on their main music business application, responsible for creating their multi-award-winning albums. This application managed to increase its users' productivity by up to 80% in some cases. In addition to this, he architected a unique ticket scanning application for their award- winning nightclub, making it the first club in the world to introduce scanned ticket entry across all streams for their clients. Coming from a musical background and being a qualified audio engineer, with experience of record production and digital audio, this post was a perfect union. He soon became a popular figure in the C# and WPF sections of the Stack Overflow, "question and answer" website, being awarded enough reputation by the community members to raise him too well within the top half percent of all users. While authoring this book and other projects has kept him away for some time, he is keen to return to continue to help new users to get to grips with WPF. About the reviewer Alex Drenea is an experienced software developer and architect with more than 15 years of experience working in various environments from enterprise to start-up. He has worked extensively with WFP since its inception in 2006 when it was still called Avalon and led teams at IBM building large scale WPF customer and enterprise applications. Following that, he continued his journey by building on his WPF knowledge to become a Windows Phone and UWP developer and published more than 20 applications in the Windows store, with over half a million downloads. For his community contributions in the Windows platform, and recently in the Azure Data platform, he has been recognized as Microsoft MVP since 2016. Packt is searching for authors like you If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea. Table of Contents Preface 1 Chapter 1: A Smarter Way of Working with WPF 7 What is MVVM and how does it help? 8 Models 8 View Models 9 Views 10 Data binding 10 So how does MVVM help? 10 Is there a downside? 11 Debunking the myth about code behind 12 Learning how to communicate again 13 Introducing the ICommand interface 15 Handling events in Attached Properties 18 Making use of delegates 20 Structuring the application code base 23 Summary 33 Chapter 2: Debugging WPF Applications 34 Utilizing the output window 35 Putting Presentation Trace Sources to work 37 Discovering inner exceptions 43 Debugging data bound values 46 Outputting values to UI controls 47 Catching changing Dependency Property values 47 Exploiting converters 49 Summary 51 Chapter 3: Writing Custom Application Frameworks 52 What is an application framework? 52 Encapsulating common functionality 53 In base classes 58 Through interfaces 61 With Extension Methods 65 In UI controls 70 With converters 74 Constructing a custom application framework 82 Separating the Data Access Layer 99 Providing services 105 Implementing Dependency Injection 108 Table of Contents Connecting Views with View Models 117 Locating View Models 119 Summary 125 Chapter 4: Becoming Proficient with Data Binding 126 Data binding basics 126 Binding path syntax 127 Escaping invalid characters 130 Exploring the Binding class 131 Directing data bound traffic 134 Binding to different sources 135 Binding with priority 139 Binding from within control templates 140 Binding source changes 141 Converting data bound values 142 Binding multiple sources to a single target property 148 Dependency Properties 152 Setting metadata 155 Declaring read-only Dependency Properties 159 Registering Attached Properties 160 Prioritizing value setting sources 162 Data templates 168 Taking complete control 172 Displaying hierarchical data 175 Data binding to enumeration collections 179 Summary 182 Chapter 5: Using the Right Controls for the Job 183 Investigating the built-in controls 183 Inheriting framework abilities 184 Laying it on the line 186 Containing controls 187 Canvas 188 DockPanel 190 Grid 193 StackPanel 199 UniformGrid 201 WrapPanel 203 Providing custom layout behavior 205 Content controls 208 Presenting content 209 Items controls 211 Adorners 217 Modifying existing controls 223 Styling 223 Being resourceful 225 Merging resources 228 [ ii ] Table of Contents Triggering changes 231 Templating controls 237 Attaching properties 243 Combining controls 246 Creating custom controls 250 Summary 258 Chapter 6: Adapting the Built-In Controls 259 Inspecting protected methods 259 Clipping the layout 265 Altering default behavior 268 Creating overridable methods 276 Tailoring to attain our requirements 278 Populating with Data 281 Progressing toward the Target 287 Highlighting the selection 292 Indicating in the Axes 292 Emphasizing the Selection 299 Summary 309 Chapter 7: Mastering Practical Animations 310 Investigating timelines 310 Introducing key-frames 320 Telling stories 324 Controlling storyboards 326 Easing functions 334 Animating along a path 340 Creating everyday animations 341 Summary 357 Chapter 8: Creating Visually Appealing User Interfaces 358 Styling applications consistently 358 Overriding default control styles 359 Using professional icons 361 Layering visuals 363 Throwing shadows 363 Declaring multiple borders 364 Reusing composite visuals 366 Reflecting light 368 Creating glowing effects 370 Putting it all together 372 Moving away from the ordinary 375 Casting reflections 375 Exploring borderless windows 378 Visualizing data 386 Livening up the UI controls 402 [ iii ] Table of Contents Summary 414 Chapter 9: Implementing Responsive Data Validation 415 Using validation rules – to do or not to do? 416 Getting to grips with validation interfaces 417 Implementing the IDataErrorInfo interface 417 Introducing the INotifyDataErrorInfo interface 434 Annotating data 443 Varying levels of validation 447 Incorporating multiple validation techniques 449 Customizing the error template 454 Avoiding UI-based validation errors 457 Keeping Synchronized with Legacy Behavior 463 Amalgamating validation and visuals

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    617 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us