MultiBinding in Silverlight 3
How to implement MultiBinding in Silverlig开发者_高级运维ht 3?
Here's an implementation that works slightly differently: http://www.olsonsoft.com/blogs/stefanolson/post/Improvements-to-Silverlight-Multi-binding-support.aspx It lets you write code like this:
<TextBlock x:Name="Block" Foreground="White" FontSize="13"
Margin="5,0,0,0">
<local:BindingUtil.MultiBindings>
<local:MultiBindings>
<local:MultiBinding TargetProperty="Text" Converter="{StaticResource TitleConverter}">
<Binding Path="Surname"/>
<Binding Path="Forename"/>
</local:MultiBinding>
<local:MultiBinding TargetProperty="Visibility" Converter="{StaticResource TitleToVisibiltyConverter}">
<Binding Path="Surname"/>
<Binding Path="Forename"/>
</local:MultiBinding>
</local:MultiBindings>
</local:BindingUtil.MultiBindings>
</TextBlock>
Ordinarily I don't like linking to people's blogs, but the code is just way too big to post.
Here's one implementation that allows up to 5 bindings: http://www.thejoyofcode.com/MultiBinding_for_Silverlight_3.aspx It lets you write code like this:
<binding:MultiBinding x:Name="mb" Converter="{StaticResource intsToBrushConverter}"
NumberOfInputs="3"
Input1="{Binding ElementName=red, Path=Value, Mode=TwoWay}"
Input2="{Binding ElementName=green, Path=Value, Mode=TwoWay}"
Input3="{Binding ElementName=blue, Path=Value, Mode=TwoWay}" />
<Border Background="{Binding ElementName=mb, Path=Output}" Margin="5"/>
精彩评论