Дизайнер Visual Studio 2010 говорит, что необработанное исключение произошло в MultiValueConverter, но я могу создать свою программу, и она отлично работает (многосвязывание также работает).WPF MultiBinding VS design exception
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 указано литые не действует. на myassemblyname.MultiEnabledToEnabled.Convert (Object [] values, Type targetType, Object parameter, CultureInfo culture) в C: ... \ Converters.cs: строка 176 в System.Windows.Data.MultiBindingExpression.TransferValue() at System.Windows.Data.MultiBindingExpression.Transfer() в System.Windows.Data.MultiBindingExpression.UpdateTarget (Boolean) includeInnerBindings в System.Windows.Data.MultiBindingExpression.AttachToContext (Boolean) LastChance в System.Windows.Data.MultiBindingExpression .MS.Internal.Data.IDataBindEngineClient.AttachToContext (Boolean lastChance) в MS.Internal.Data.DataBindEngine.Task.Run (Boolean lastChance) в MS.Internal.Data.DataBindEngine.Run (Object arg) в системе. Windows.Threading.Excep tionWrapper.InternalRealCall (делегат обратного вызова, арг Object, Int32 numArgs) в MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen (источник объекта, метод делегата, объект арг, Int32 numArgs, делегат catchHandler)