无法设置多重绑定,因为必须指定多值转换器wpf

时间:2016-09-18 19:00:29

标签: c# wpf prism

好的,关于这个问题,我已经按照以下两篇帖子[ Post 1 Post 2 ]进行了讨论。但是,即使遵循正确的实施方式,这个问题仍然让我大吃一惊。

所以这是我的转换器,它被添加到项目的ViewModels目录中:

public class ChangePasswordConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        return ....
    }

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

现在下面是我的HomeWindow.xaml

<Controls:MetroWindow x:Class="KEOffice.Views.HomeWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    xmlns:v="clr-namespace:KEOffice.Views"
    xmlns:vm="clr-namespace:KEOffice.ViewModels"
    xmlns:prism="http://prismlibrary.com/"
    prism:ViewModelLocator.AutoWireViewModel="True">

    <Window.Resources>
        <vm:ChangePasswordConverter x:Key="ChangePasswordConverter" />
    </Window.Resources>
    <!--But when I try to do this-->
    <Button Command="{Binding ChangePassword.UpdatePassword}">
           <Button.CommandParameter>
               <MultiBinding ConverterParameter="{StaticResource ChangePasswordConverter}">
                   <Binding Path="OldPass" ElementName="OldPass"/>
                   <Binding Path="NewPass" ElementName="NewPass"/>
                   <Binding Path="ConfirmPass" ElementName="ConfirmPass"/>
               </MultiBinding>
          </Button.CommandParameter>
    </Button>
</Controls:MetroWindow>

即使我已正确引用viewmodels,转换器存在且指定有效StaticResource,它也会引发Cannot set multibinding because multivalue converter must be specified。我也做过重建,清理重建等,但仍然是同样的问题。我需要注意什么才能使其正常工作?

1 个答案:

答案 0 :(得分:1)

您不使用ConverterParameter来指定转换器,而是使用Converter。