MultiBinding
CodeKeep C# Feed Maggio 25th, 2008
Description: WPF MultiBinding with Converter
Link: http://www.codekeep.net/snippets/e1d1225a-a857-452d-9136-27c47980cb5f.aspx
<Rectangle Name="rtColor" Margin="25">
<Rectangle.Fill>
<SolidColorBrush>
<SolidColorBrush.Color>
<MultiBinding Converter="{StaticResource convertColor}">
<MultiBinding.Bindings>
<Binding ElementName="slAlpha" Path="Value" />
<Binding ElementName="slRed" Path="Value" />
<Binding ElementName="slGreen" Path="Value" />
<Binding ElementName="slBlue" Path="Value" />
</MultiBinding.Bindings>
</MultiBinding>
</SolidColorBrush.Color>
</SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
<Window.Resources>
<local:ConvertColor x:Key="convertColor" />
<ImageBrush x:Key="newtelligencelogo" TileMode="Tile" Viewport="0,0,240,51" ViewportUnits="Absolute" ImageSource= "newtelligencelogo.bmp"/>
</Window.Resources>
public class ConvertColor : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
float alpha = (float)(double)(values[0]);
float red = (float)(double)(values[1]);
float green = (float)(double)(values[2]);
float blue = (float)(double)(values[3]);
return Color.FromScRgb(alpha, red, green, blue);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException("Not supported");
}
}






