Book Image

Windows Presentation Foundation Development Cookbook

Book Image

Windows Presentation Foundation Development Cookbook

Overview of this book

Windows Presentation Foundation (WPF) is Microsoft's development tool for building rich Windows client user experiences that incorporate UIs, media, and documents. With the updates in .NET 4.7, Visual Studio 2017, C# 7, and .NET Standard 2.0, WPF has taken giant strides and is now easier than ever for developers to use. If you want to get an in-depth view of WPF mechanics and capabilities, then this book is for you. The book begins by teaching you about the fundamentals of WPF and then quickly shows you the standard controls and the layout options. It teaches you about data bindings and how to utilize resources and the MVVM pattern to maintain a clean and reusable structure in your code. After this, you will explore the animation capabilities of WPF and see how they integrate with other mechanisms. Towards the end of the book, you will learn about WCF services and explore WPF's support for debugging and asynchronous operations. By the end of the book, you will have a deep understanding of WPF and will know how to build resilient applications.
Table of Contents (13 chapters)
2
Using WPF Standard Controls

How to do it...

Perform the following steps to create a simple Canvas panel with a few label controls in it and position them to specific coordinate positions:

  1. Open Solution Explorer and navigate to the project.
  2. Open the MainWindow.xaml file and replace the default Grid with the following lines:
<Canvas> 
    <Label Width="100" Height="60" 
           Background="GreenYellow"  
           Canvas.Left="70" Canvas.Top="40" 
           Content="(70, 40)" 
           FontSize="20" FontWeight="Bold"/> 
    <Label Width="100" Height="60" 
           Background="YellowGreen"  
           Canvas.Left="220" Canvas.Top="90" 
           Content="(220, 90)" 
           FontSize="20" FontWeight="Bold"/> 
</Canvas> 
  1. Build and run the application. It will show the following screen:
  1. Now resize the window and observe...