【问题标题】:Cannot set multibinding because multivalue converter must be specified wpf无法设置多重绑定,因为必须指定多值转换器 wpf
【发布时间】:2016-09-18 19:00:29
【问题描述】:

好的,在关注了关于这个问题的这两个帖子 [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。我也做了重建,清理重建等,但仍然是同样的问题。我还需要注意什么才能使其正常工作?

【问题讨论】:

    标签: c# wpf prism


    【解决方案1】:

    你不使用ConverterParameter来指定转换器,你使用Converter。

    【讨论】:

    • 该死的人.. 那个属性.. :( 感谢您的快速回答... :)
    猜你喜欢
    • 2013-10-30
    • 2011-03-13
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    • 2019-04-22
    • 2018-10-26
    • 2015-01-20
    • 1970-01-01
    相关资源
    最近更新 更多