2010-03-25 43 views

回答

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> 

通常我不喜歡鏈接到人們的博客,但代碼太大而無法發佈。

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"/>