Intersoft.Client.Framework Namespace : MultiBinding Class |
<ContentPropertyAttribute("Bindings")> Public Class MultiBinding Inherits ISBindingContainer
Dim instance As MultiBinding
[ContentPropertyAttribute("Bindings")] public class MultiBinding : ISBindingContainer
[ContentPropertyAttribute("Bindings")] public ref class MultiBinding : public ISBindingContainer
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> |
System.Object
System.Windows.DependencyObject
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Controls.Panel
Intersoft.Client.Framework.ISBindingContainer
Intersoft.Client.Framework.MultiBinding
Target Platforms: 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