tnw
tnw

Reputation: 13877

PresentationFramework in Silverlight 5

I need some help figuring out an issue I'm having implementing a MultiBooleanConverter in Silverlight 5. I have the implementation, but getting the right references is causing me some trouble.

Here's my code for starters.

XAML:

<telerikRibbonView:RadRibbonButton.Visibility>
     <MultiBinding Converter="{StaticResource MultiBooleanToVisibilityConverter}">
          <Binding Path="Path1" />
          <Binding Path="Path2" />
     </MultiBinding>
</telerikRibbonView:RadRibbonButton.Visibility>

Converter (Credit):

class MultiBooleanToVisibilityConverter : IMultiValueConverter
{
    public object Convert(object[] values,
                            Type targetType,
                            object parameter,
                            System.Globalization.CultureInfo culture)
    {
        bool visible = true;
        foreach (object value in values)
            if (value is bool)
                visible = visible && (bool)value;

        if (visible)
            return System.Windows.Visibility.Visible;
        else
            return System.Windows.Visibility.Collapsed;
    }

    public object[] ConvertBack(object value,
                                Type[] targetTypes,
                                object parameter,
                                System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Issue I'm having is that the IMultiValueConverter interface resides in the namespace System.Windows.Data, which resides in the PresentationFramework dll, which I cannot add as a reference in my Silverlight project because it's not built against Silverlight.

I apologize if I'm totally missing something obvious. How can I use IMultiValueConverter in Silverlight? Is there a different DLL I need instead?

Also, all my other interfaces implement IValueConverter which also live in System.Windows.Data but are pulled from the System.Windows.Data dll in c:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Libraries\Client\ which is NOT the assembly I need for IMultiValueConverter. Having an ambiguous System.Windows.Data namespace shouldn't be an issue, however, as I can just use Alias binding to resolve the ambiguity. I just need to figure out how to get IMultiValueConverter in Silverlight.

Upvotes: 1

Views: 1229

Answers (1)

EkoostikMartin
EkoostikMartin

Reputation: 6911

Unfortunately Silverlight doesn't have a framework implementation of the Multibinding scenario, so you have to write more of the code yourself.

Here is a article including some pretty clean code to do this though - http://www.scottlogic.com/blog/2010/05/10/silverlight-multibinding-solution-for-silverlight-4.html

It includes the code to explicitly define the same interface, which you could then use with your code above:

  public interface IMultiValueConverter
  {   
      object Convert(object[] values, Type targetType, object parameter, 
                      CultureInfo culture);

      object[] ConvertBack(object value, Type[] targetTypes, object parameter,
                           CultureInfo culture);       
  }

Upvotes: 2

Related Questions