Visual Studio 2010 デザイナーは、MultiValueConverter で未処理の例外が発生したと言っていますが、プログラムをビルドでき、正常に動作します (マルチバインディングも動作します)。
XAML (コンストラクターで window.DataContext を設定):
<ComboBox Name="cbbProfile" DisplayMemberPath="Name" Grid.Row="1" Margin="10,5" Grid.ColumnSpan="3" ItemsSource="{Binding ProfilesData.ProfilesItems}" SelectionChanged="cbbProfile_SelectionChanged" >
<ComboBox.IsEnabled>
<MultiBinding Converter="{StaticResource multiEnabledToEnabled}">
<Binding Path="ProfilesData.ProfilesItems.Count" Converter="{StaticResource itemsCountToEnabled}" />
<Binding Path="State" Converter="{StaticResource stateToControlsEnabled}" />
</MultiBinding>
</ComboBox.IsEnabled>
</ComboBox>
コンバーター:
public class MultiEnabledToEnabled : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
foreach (object val in values)
{
if (!(bool) val) // <-- EXCEPTION (line 176) HERE
return false;
}
return true;
}
public class ItemsCountToEnabled : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (int)value == 0 ? false : true;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class StateToControlsEnabled : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var val = (ProgramState)value;
switch (val)
{
...
default:
return true;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
VS 例外テキスト:
System.InvalidCastException 指定されたキャストは無効です。System.Windows の System.Windows.Data.MultiBindingExpression.TransferValue() の C:...\Converters.cs:line 176 の myassemblyname.MultiEnabledToEnabled.Convert(Object[] values, Type targetType, Object parameter, CultureInfo culture) でSystem.Windows.Data.MultiBindingExpression.UpdateTarget の .Data.MultiBindingExpression.Transfer() (Boolean includeInnerBindings) System.Windows.Data.MultiBindingExpression.AttachToContext(Boolean lastChance) の System.Windows.Data.MultiBindingExpression.MS.Internal.Data System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate) で MS.Internal.Data.DataBindEngine.Run(Object arg) で MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance) で .IDataBindEngineClient.AttachToContext(Boolean lastChance)コールバック、オブジェクト引数、