Intersoft ClientUI Documentation
MultiBinding Class
Members  See Also  Send Feedback
Intersoft.Client.Framework Namespace : MultiBinding Class






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

Object Model

MultiBinding Class

Syntax

Visual Basic (Declaration) 
<ContentPropertyAttribute("Bindings")>
Public Class MultiBinding 
   Inherits ISBindingContainer
Visual Basic (Usage)Copy Code
Dim instance As MultiBinding
C# 
[ContentPropertyAttribute("Bindings")]
public class MultiBinding : ISBindingContainer 
Delphi 
public class MultiBinding = class(ISBindingContainer)
JScript 
ContentPropertyAttribute("Bindings")
public class MultiBinding extends ISBindingContainer
Managed Extensions for C++ 
[ContentPropertyAttribute("Bindings")]
public __gc class MultiBinding : public ISBindingContainer 
C++/CLI 
[ContentPropertyAttribute("Bindings")]
public ref class MultiBinding : public ISBindingContainer 

Example

The following code example shows how to create a multi-value converter class that implements IMultiValueConverter to provide conversion from FirstName and LastName into a single formatted value.

C# Copy Code
public class NameConverter : IMultiValueConverter
{

    #region IMultiValueConverter Members

    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        string firstName = string.Empty;
        string lastName = string.Empty;
        string fullName = string.Empty;

        if (values == null || values.Length == 0)
            return string.Empty;

        if (values.GetValue(0) != null)
            firstName = values.GetValue(0).ToString();

        if (values.GetValue(1) != null)
            lastName = values.GetValue(1).ToString();

        if (!string.IsNullOrEmpty(firstName) && !string.IsNullOrEmpty(lastName))
            fullName = lastName + ", " + firstName;
        else if (!string.IsNullOrEmpty(firstName))
            fullName = firstName;
        else if (!string.IsNullOrEmpty(lastName))
            fullName = lastName;
        else
            fullName = "Please specify a name";

        return fullName;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    #endregion
}

Once the multi-value converters are defined, you can consume them in the XAML pages and declare the MultiBinding in the elements.

The following XAML code shows how to declare the converter as a static resource in the XAML page, and declare the MultiBinding as well as the multiple {Binding} definition on the Text property on the Content property of a GlassLabel control.

XAML Copy Code
<Intersoft:UXPage 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        xmlns:Intersoft="http://intersoft.clientui.com/schemas"
          xmlns:Converters="clr-namespace:TestcaseMVVM.Converters"
        x:Class="TestcaseMVVM.Views.MultiBindings" 
        Title="MultiBindings Page"
        d:DesignWidth="640" d:DesignHeight="480">
    
    <Intersoft:UXPage.Resources>
        
        <Converters:NameConverter x:Key="NameConverter"/>
        
    </Intersoft:UXPage.Resources>

    <Grid x:Name="LayoutRoot">
        <Border VerticalAlignment="Center" HorizontalAlignment="Center"
                     Background="White" CornerRadius="4" Width="300" Height="200">

            <Intersoft:DockPanel>

                <Intersoft:GlassLabel Intersoft:DockPanel.Dock="Top" CornerRadius="4,4,0,0">
                    <Intersoft:BindingFramework.MultiBinding>
                        <Intersoft:MultiBinding TargetProperty="Content" Converter="{StaticResource NameConverter}">
                            <Intersoft:BindingCollection>
                                <Binding Path="Text" ElementName="FirstName_Input"/>
                                <Binding Path="Text" ElementName="LastName_Input"/>
                            </Intersoft:BindingCollection>
                        </Intersoft:MultiBinding>
                    </Intersoft:BindingFramework.MultiBinding>
                </Intersoft:GlassLabel>

                <Intersoft:UXItemsControl Margin="8">
                    <Intersoft:FieldLabel Header="First Name:" HeaderWidth="100">
                        <Intersoft:UXTextBox Name="FirstName_Input" Text="John" Width="150"/>
                    </Intersoft:FieldLabel>
                    <Intersoft:FieldLabel Header="Last Name:" HeaderWidth="100">
                        <Intersoft:UXTextBox Name="LastName_Input" Text="Smith" Width="150"/>
                    </Intersoft:FieldLabel>
                    <Intersoft:FieldLabel Header="Title:" HeaderWidth="100">
                        <Intersoft:UXTextBox Width="100" Text="Mr."/>
                    </Intersoft:FieldLabel>
                    <Intersoft:FieldLabel Header="Age:" HeaderWidth="100">
                        <Intersoft:UXNumericUpDown Width="50" Value="25"/>
                    </Intersoft:FieldLabel>
                </Intersoft:UXItemsControl>
            </Intersoft:DockPanel>

        </Border>
    </Grid>

</Intersoft:UXPage>

 

Remarks

For more information about MultiBinding, see Introduction to Multi Binding. 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.

Inheritance Hierarchy

System.Object
   System.Windows.DependencyObject
      System.Windows.UIElement
         System.Windows.FrameworkElement
            System.Windows.Controls.Panel
               Intersoft.Client.Framework.ISBindingContainer
                  Intersoft.Client.Framework.MultiBinding

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2012 All Rights Reserved.