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

Using a timer to periodically update the UI

It is often require to update a portion of the user interface periodically. In that case, a timer object is beneficial to keep the UI refreshed. For example, in your application, you may want to show the current time at some part of the UI. For this, you can use a timer to periodically update the UI without the need to create a different thread.

The System.Windows.Threading.DispatcherTimer class can be used to integrate into the Dispatcher queue, and can process at a specified interval of time and at a specified priority.

In this recipe, we will use the DispatcherTimer class to implement a timer, which will execute its subscribed Tick event each time the specified Interval is met.