MultiBinding Class

Describes a collection of Binding objects attached to a single binding target property.

Namespace:  System.Windows.Data
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

[<ContentPropertyAttribute("Bindings")>]
type MultiBinding =  
    class
        inherit BindingBase
        interface IAddChild
    end
<MultiBinding>
  Bindings
</MultiBinding>

The MultiBinding type exposes the following members.

  NameDescription
Public methodMultiBindingInitializes a new instance of the MultiBinding class.
Top

  NameDescription
Public propertyBindingGroupNameGets or sets the name of the BindingGroup to which this binding belongs. (Inherited from BindingBase.)
Public propertyBindingsGets the collection of Binding objects within this MultiBinding instance.
Public propertyConverterGets or sets the converter to use to convert the source values to or from the target value.
Public propertyConverterCultureGets or sets the CultureInfo object that applies to any converter assigned to bindings wrapped by the MultiBinding or on the MultiBinding itself.
Public propertyConverterParameterGets or sets an optional parameter to pass to a converter as additional information.
Public propertyFallbackValueGets or sets the value to use when the binding is unable to return a value. (Inherited from BindingBase.)
Public propertyModeGets or sets a value that indicates the direction of the data flow of this binding.
Public propertyNotifyOnSourceUpdatedGets or sets a value that indicates whether to raise the SourceUpdated event when a value is transferred from the binding target to the binding source.
Public propertyNotifyOnTargetUpdatedGets or sets a value that indicates whether to raise the TargetUpdated event when a value is transferred from the binding source to the binding target.
Public propertyNotifyOnValidationErrorGets or sets a value that indicates whether to raise the Error attached event on the bound element.
Public propertyStringFormatGets or sets a string that specifies how to format the binding if it displays the bound value as a string. (Inherited from BindingBase.)
Public propertyTargetNullValueGets or sets the value that is used in the target when the value of the source is a null reference (Nothing in Visual Basic). (Inherited from BindingBase.)
Public propertyUpdateSourceExceptionFilterGets or sets a handler you can use to provide custom logic for handling exceptions that the binding engine encounters during the update of the binding source value. This is only applicable if you have associated the ExceptionValidationRule with your MultiBinding object.
Public propertyUpdateSourceTriggerGets or sets a value that determines the timing of binding source updates.
Public propertyValidatesOnDataErrorsGets or sets a value that indicates whether to include the DataErrorValidationRule.
Public propertyValidatesOnExceptionsGets or sets a value that indicates whether to include the ExceptionValidationRule.
Public propertyValidationRulesGets the collection of ValidationRule objects for this instance of MultiBinding.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodProvideValueReturns an object that should be set on the property where this binding and extension are applied. (Inherited from BindingBase.)
Public methodShouldSerializeBindingsIndicates whether the Bindings property should be persisted.
Public methodShouldSerializeFallbackValueReturns a value that indicates whether serialization processes should serialize the effective value of the FallbackValue property on instances of this class. (Inherited from BindingBase.)
Public methodShouldSerializeTargetNullValueReturns a value that indicates whether the TargetNullValue property should be serialized. (Inherited from BindingBase.)
Public methodShouldSerializeValidationRulesIndicates whether the ValidationRules property should be persisted.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIAddChild.AddChildInfrastructure. Adds a child object.
Explicit interface implemetationPrivate methodIAddChild.AddTextInfrastructure. Adds the text content of a node to the object.
Top

You can specify multiple bindings in a MultiBinding object. When you use the MultiBinding object with a converter, it produces a final value for the binding target based on the values of those bindings. For example, color might be computed from red, blue, and green values, which can be values from the same or different binding source objects. When a value moves from the target to the sources, the target property value is translated to a set of values that are fed back into the bindings.

The values of the Mode and UpdateSourceTrigger properties determine the functionality of the MultiBinding and are used as the default values for all the bindings in the collection unless an individual binding overrides these properties. For example, if the Mode property on the MultiBinding object is set to TwoWay, then all the bindings in the collection are considered TwoWay unless you set a different Mode value on one of the bindings explicitly. For more information, see the Binding.Mode and Binding.UpdateSourceTrigger properties.

MultiBinding currently supports only objects of type Binding and not MultiBinding or PriorityBinding.

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 MultiBinding.

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 TextBlock that shows the first and last names of a person with the last name first.


<Window
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:c="clr-namespace:SDKSample"
  x:Class="SDKSample.Window1"
  Width="400"
  Height="280"
  Title="MultiBinding Sample">
	
  <Window.Resources>
    <c:NameList x:Key="NameListData"/>
    <c:NameConverter x:Key="myNameConverter"/>


...


</Window.Resources>


...


<TextBlock Name="textBox2" DataContext="{StaticResource NameListData}">
  <TextBlock.Text>
    <MultiBinding Converter="{StaticResource myNameConverter}"
                  ConverterParameter="FormatLastFirst">
      <Binding Path="FirstName"/>
      <Binding Path="LastName"/>
    </MultiBinding>
  </TextBlock.Text>
</TextBlock>


...


</Window>


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

No code example is currently available or this language may not be supported.

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

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft