【发布时间】: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。我也做了重建,清理重建等,但仍然是同样的问题。我还需要注意什么才能使其正常工作?
【问题讨论】: