Click here to Skip to main content
15,908,776 members
Articles / Desktop Programming / WPF

Introduction to Multi-binding and Multi-value Converters using IMultiValueConverter and MultiBinding

Rate me:
Please Sign up or sign in to vote.
5.00/5 (10 votes)
12 Feb 2012CPOL2 min read 213.6K   10   6
MultiBinding allows us to bind a binding target property to a list of source properties and then apply logic to produce a value with the given inputs.

For an introduction to Value Converters, see the post here.

For more information on mode property, see the post on mode here.

MultiBinding allows us 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. The following example produces a TextBox that adds the numbers in TextBox1 and TextBox2 and puts the result into TextBox3. Here, we have two source properties and one target property. When you enter numbers in the TextBox1 and TextBox2, the converter comes into play and automatically adds them and puts the result into TextBox3. 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.

In the following code, AddConverter implements the IMultiValueConverter interface. AddConverter 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.

Figure 1: Important classes hierarchy

Figure 2: Binding classes hierarchy

The XAML for the above mentioned logic is as follows:

<Window x:Class="DataConversion.MainWindow"
        Title="MainWindow" Height="350" Width="525"
            <mylocalXAMLnamespace:AddConverter x:Key="XAMLResourceAddConverter" />

        <TextBox Name="TextBox1" Text="10"></TextBox>
        <TextBox Name="TextBox2" Text="20"></TextBox>
        <Label Content="Sum of above two values:"></Label>
        <TextBox Name="textBox3">
                <MultiBinding Converter="{StaticResource XAMLResourceAddConverter}">
                    <Binding ElementName="TextBox1" Path="Text"/>
                    <Binding ElementName="TextBox2" Path="Text"/>

The MultiBinding tag takes binding as a parameter. See the following C# code that does the binding.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Markup;

namespace DataConversion
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        public MainWindow()
    public class AddConverter : IMultiValueConverter
        public object Convert(object[] values, Type targetType, 
               object parameter, System.Globalization.CultureInfo culture)
            int result = 
                Int32.Parse((string)values[0]) + Int32.Parse((string)values[1]);
            return result.ToString();
        public object[] ConvertBack(object value, Type[] targetTypes, 
               object parameter, System.Globalization.CultureInfo culture)
            throw new NotSupportedException("Cannot convert back");

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.

Download the source code from here.

If it’s a good idea, go ahead and do it. It is much easier to apologize than it is to get permission.
- Admiral Grace Hopper.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
CEO Astrani Technology Solutions
United States United States
Kishore Babu Gaddam is a Senior Technology Consultant, Technology Evangelist turned Technology Entrepreneur and a regular speaker at national conferences, regional code camps and local user groups with over 14 years of experience in software product development. His experience includes building & managing award-winning software development teams, managing customer relationships, marketing and launching new software products & services. Kishore launched his technology career almost 15 years ago with a Robotics software development startup and has served in multiple roles since including developer, innovation leader, consultant, technology executive and business owner.

A technology specialist in C++, C#, XAML and Azure, he successfully published two applications to Windows store and

Kishore is the author of the popular Microsoft Technologies blog at and his work on Portable Class Library project in Visual Studio 2012– .NET 4.5 was featured on Channel 9 at Kishore enjoys helping people understand technical concepts that may initially seem complex and perform lot of Research & Development on emerging technologies to help solve some of the toughest customer issues. Kishore spends a lot of time teaching and mentoring developers to learn new technologies and to be better developers. He is a speaker at various code camps around Washington DC area, mainly at Microsoft Technology Center for NOVA code camp (, CMAP Code Camp Fall 2012 (, etc. The majority of his software development experience has centered on Microsoft technologies including MFC, COM, COM+, WCF, WPF, winRT, HTML5, RestAPI and SQL Server. You can follow Kishore on Twitter at He can be reached on email at

Comments and Discussions

QuestionGreat guide! One question Pin
Member 1306979719-Mar-17 12:19
Member 1306979719-Mar-17 12:19 
GeneralMy vote of 5 Pin
sbarnes20-Dec-15 23:40
sbarnes20-Dec-15 23:40 
SuggestionMessage Closed Pin
3-Dec-13 7:01
ybonda3-Dec-13 7:01 
GeneralRe: Download source code Pin
kishore Gaddam14-Feb-14 3:57
kishore Gaddam14-Feb-14 3:57 
GeneralMy vote of 5 Pin
PepLamb29-Nov-12 11:18
PepLamb29-Nov-12 11:18 
GeneralRe: My vote of 5 Pin
kishore Gaddam30-Nov-12 7:50
kishore Gaddam30-Nov-12 7:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.