假?使用同时是IMultiValueConverter和MarkupExtension的MutiBinding Converter时出错

时间:2015-12-16 18:51:22

标签: c# wpf xaml data-binding visual-studio-2015

我正在使用Visual Studio 2015.每当我尝试在XAML中使用也是MarkupExtension的{​​{1}}时,我会在错误列表窗口中看到以下错误消息:

  

无法设置MultiBinding,因为必须指定MultiValueConverter

尽管使用red-X错误图标显示了这一点,但应用程序仍然构建并运行正常,据我所知,代码没有任何问题。这是一个足以触发它的简短片段:

namespace MyApp
{
    using System;
    using System.Globalization;
    using System.Windows;
    using System.Windows.Data;
    using System.Windows.Markup;

    [MarkupExtensionReturnType(typeof(TestConverter))]
    // using typeof(IMultiValueConverter) doesn't help
    public class TestConverter : MarkupExtension, IMultiValueConverter
    {
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            return DependencyProperty.UnsetValue;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            return new[] {DependencyProperty.UnsetValue};
        }
    }
}
<Page x:Class="MyApp.TestPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:MyApp"
      mc:Ignorable="d" 
      Title="TestPage">

    <Grid>
        <TextBlock>
            <TextBlock.Text>
                <!-- Next 4 lines are underlined in blue with the message shown -->
                <MultiBinding Converter="{local:TestConverter}">
                    <Binding />
                    <Binding />
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>
    </Grid>
</Page>

我在这里遗漏了什么(属性?)或者这是VS解析器中的错误?

0 个答案:

没有答案