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 it works...

Though a ComboBox control is like ListBox, it does not show the list of items by default. A user intervention is required to display the items. The UI of a ComboBox is a combination of three controls:

  • A TextBox, which displays the selected item
  • A Button, which is used to show or hide available items
  • A Popup, which displays a list of items inside a scrollable pane and gives the user the option to select one item from the available list

ComboBox contains a collection of ComboBoxItem. You can add those to its Items property. When you click on the arrow-head, the list of items will pop up in the screen, as demonstrated in the preceding screenshot. To preselect an item from code, set its IsSelected property to True.

You can also add custom contents to a ComboBoxItem to represent a better UI component. The second ComboBox in the preceding example, demonstrates how easy it is to customize the UI.

Just like ListBox, it also exposes SelectedItem, SelectedIndex, SelectedValue...