Home
Manage Your Code
Snippet: MultiBinding (C#)
Title: MultiBinding Language: C#
Description: WPF MultiBinding with Converter Views: 222
Author: sudhakar kalmari Date Added: 5/24/2008
Copy Code  
1<Rectangle Name="rtColor" Margin="25">
2
3  <Rectangle.Fill>
4
5    <SolidColorBrush>
6
7      <SolidColorBrush.Color>
8
9        <MultiBinding Converter="{StaticResource convertColor}">
10
11          <MultiBinding.Bindings>
12
13            <Binding ElementName="slAlpha" Path="Value" />
14
15            <Binding ElementName="slRed" Path="Value" />
16
17            <Binding ElementName="slGreen" Path="Value" />
18
19            <Binding ElementName="slBlue" Path="Value" />
20
21          </MultiBinding.Bindings>
22
23        </MultiBinding>
24
25      </SolidColorBrush.Color>
26
27    </SolidColorBrush>
28
29  </Rectangle.Fill>
30
31</Rectangle>
32
33
34
35<Window.Resources>
36
37  <local:ConvertColor x:Key="convertColor" />
38
39  <ImageBrush x:Key="newtelligencelogo" TileMode="Tile" Viewport="0,0,240,51" ViewportUnits="Absolute" ImageSource= "newtelligencelogo.bmp"/>
40
41</Window.Resources>
42
43
44
45
46public class ConvertColor : IMultiValueConverter
47
48{
49
50    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
51
52    {
53
54        float alpha = (float)(double)(values[0]);
55
56        float red = (float)(double)(values[1]);
57
58        float green = (float)(double)(values[2]);
59
60        float blue = (float)(double)(values[3]);
61
62 
63
64        return Color.FromScRgb(alpha, red, green, blue);
65
66    }
67
68 
69
70    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
71
72    {
73
74        throw new NotSupportedException("Not supported");
75
76    }
77
78}
79
80