如何在Silverlight 3中实现MultiBinding?
答案 0 :(得分:3)
这是一种工作方式略有不同:http://www.olsonsoft.com/blogs/stefanolson/post/Improvements-to-Silverlight-Multi-binding-support.aspx 它允许你编写这样的代码:
<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>
通常我不喜欢链接到人们的博客,但代码太大而无法发布。
答案 1 :(得分:0)
这是一个允许最多5个绑定的实现:http://www.thejoyofcode.com/MultiBinding_for_Silverlight_3.aspx 它允许你编写这样的代码:
<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"/>