【问题标题】:PresentationFramework in Silverlight 5Silverlight 5 中的 PresentationFramework
【发布时间】:2013-07-09 20:52:23
【问题描述】:

我需要一些帮助来解决我在 Silverlight 5 中实现 MultiBooleanConverter 时遇到的问题。我有实现,但是获取正确的引用给我带来了一些麻烦。

这是我的初学者代码。

XAML:

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

转换器 (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();
    }
}

我遇到的问题是IMultiValueConverter 接口位于命名空间System.Windows.Data 中,该命名空间位于PresentationFramework dll 中,我无法在我的Silverlight 项目中添加它作为引用,因为它不是针对Silverlight 构建的。

如果我完全遗漏了一些明显的东西,我深表歉意。如何在 Silverlight 中使用 IMultiValueConverter?我需要其他 DLL 吗?

另外,我所有的其他接口都实现了IValueConverter,它存在于System.Windows.Data,但从c:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Libraries\Client\ 中的System.Windows.Data dll 中提取,这不是@987654331 我需要的程序集@。但是,有一个模棱两可的 System.Windows.Data 命名空间应该不是问题,因为我可以使用别名绑定来解决模棱两可的问题。我只需要弄清楚如何在 Silverlight 中获取 IMultiValueConverter

【问题讨论】:

    标签: c# silverlight xaml


    【解决方案1】:

    很遗憾,Silverlight 没有 Multibinding 场景的框架实现,因此您必须自己编写更多代码。

    这是一篇文章,其中包含一些非常干净的代码来执行此操作 - http://www.scottlogic.com/blog/2010/05/10/silverlight-multibinding-solution-for-silverlight-4.html

    它包含显式定义相同接口的代码,然后您可以将其与上面的代码一起使用:

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

    【讨论】:

    • 天哪……好吧。感谢您的信息!
    猜你喜欢
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-17
    • 1970-01-01
    相关资源
    最近更新 更多