Files
docs-desktop/dotnet-desktop-guide/framework/wpf/data/how-to-produce-a-value-based-on-a-list-of-bound-items.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

2.6 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Produce a Value Based on a List of Bound Items 03/30/2017
csharp
vb
data binding [WPF], MultiBinding
Multibinding [WPF]
b3d06378-b511-4181-95aa-316d60c9229b

How to: Produce a Value Based on a List of Bound Items

xref:System.Windows.Data.MultiBinding allows you to bind a binding target property to a list of source properties and then apply logic to produce a value with the given inputs. This example demonstrates how to use xref:System.Windows.Data.MultiBinding.

Example

In the following example, NameListData refers to a collection of PersonName objects, which are objects that contain two properties, firstName and lastName. The following example produces a xref:System.Windows.Controls.TextBlock that shows the first and last names of a person with the last name first.

[!code-xamlMultiBinding#Resources1]
[!code-xamlMultiBinding#Resources2]
[!code-xamlMultiBinding#MultiBindingTextBox2]
[!code-xamlMultiBinding#Window]

To understand how the last-name-first format is produced, let's take a look at the implementation of the NameConverter:

[!code-csharpMultiBinding#3] [!code-vbMultiBinding#3]

NameConverter implements the xref:System.Windows.Data.IMultiValueConverter interface. NameConverter takes the values from the individual bindings and stores them in the values object array. The order in which the xref:System.Windows.Data.Binding elements appear under the xref:System.Windows.Data.MultiBinding element is the order in which those values are stored in the array. The value of the xref:System.Windows.Data.MultiBinding.ConverterParameter%2A attribute is referenced by the parameter argument of the xref:System.Windows.Data.MultiBinding.Converter%2A method, which performs a switch on the parameter to determine how to format the name.

See also