Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Windows Presentation Foundation

You're reading from   Mastering Windows Presentation Foundation Build responsive UIs for desktop applications with WPF

Arrow left icon
Product type Paperback
Published in Mar 2020
Publisher Packt
ISBN-13 9781838643416
Length 626 pages
Edition 2nd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Sheridan Yuen Sheridan Yuen
Author Profile Icon Sheridan Yuen
Sheridan Yuen
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. A Smarter Way of Working with WPF 2. Debugging WPF Applications FREE CHAPTER 3. Writing Custom Application Frameworks 4. Becoming Proficient with Data Binding 5. Using the Right Controls for the Job 6. Adapting the Built-In Controls 7. Mastering Practical Animations 8. Creating Visually Appealing User Interfaces 9. Implementing Responsive Data Validation 10. Completing that Great User Experience 11. Improving Application Performance 12. Deploying Your Masterpiece Application 13. What Next? 14. Other Books You May Enjoy

Data templates

We've already seen a number of simple examples of the DataTemplate, but they are such an important part of WPF that we're going to have a much more thorough look at them now. In short, we use a DataTemplate to define how we want particular data objects to be rendered in the UI.

If we were to data bind a particular type of object to a UI control without providing a DataTemplate for it, the WPF Framework would not know how to display it. Let's highlight this with an example:

<ItemsControl ItemsSource="{Binding Users}" /> 

In these cases, the best job that the WPF Framework can do is to display a string representation of each object. It achieves this by calling the object.ToString method on the data object and setting that value to the Text property of a TextBlock, which it uses to display the object. If this method has not been overridden in the object's class, this will result in the name of the type of the object being displayed in its...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime