У меня есть поле со списком размеров шрифтов, которые я пытаюсь связать с моделью представления MVVM.Свойство SelectedItem привязано к моему свойству модели Viwe, FontSize.Раскрывающийся список исправлен, поэтому я объявляю элементы поля со списком в XAML для поля со списком, например:
<ComboBox SelectedItem="{Binding Path=FontSize, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
Width="60" Margin="2,0,3,0">
<ComboBoxItem Content="10" />
<ComboBoxItem Content="12" />
<ComboBoxItem Content="18" />
<ComboBoxItem Content="24" />
<ComboBoxItem Content="36" />
<ComboBoxItem Content="48" />
<ComboBoxItem Content="60" />
<ComboBoxItem Content="72" />
</ComboBox>
Вот моя проблема: при запуске приложения загружаются элементы со спискомхорошо.Но когда я выбираю элемент из списка, я получаю эту ошибку в окне «Вывод»:
Int32Converter cannot convert from System.Windows.Controls.ComboBoxItem.
Другие привязки данных в окне работают нормально.Полное сообщение об ошибке перепечатано ниже.
Что говорит мне сообщение об ошибке, и как мне это исправить?Заранее благодарим за помощь.
Полное сообщение об ошибке:
System.Windows.Data Error: 23 : Cannot convert 'System.Windows.Controls.ComboBoxItem: 12' from type 'ComboBoxItem' to type 'System.Int32' for 'en-US' culture with default conversions; consider using Converter property of Binding. NotSupportedException:'System.NotSupportedException: Int32Converter cannot convert from System.Windows.Controls.ComboBoxItem.
at System.ComponentModel.TypeConverter.GetConvertFromException(Object value)
at System.ComponentModel.TypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)'
System.Windows.Data Error: 7 : ConvertBack cannot convert value 'System.Windows.Controls.ComboBoxItem: 12' (type 'ComboBoxItem'). BindingExpression:Path=FontSize; DataItem='MainWindowViewModel' (HashCode=14640006); target element is 'ComboBox' (Name=''); target property is 'SelectedItem' (type 'Object') NotSupportedException:'System.NotSupportedException: Int32Converter cannot convert from System.Windows.Controls.ComboBoxItem.
at MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)
at MS.Internal.Data.ObjectTargetConverter.ConvertBack(Object o, Type type, Object parameter, CultureInfo culture)
at System.Windows.Data.BindingExpression.ConvertBackHelper(IValueConverter converter, Object value, Type sourceType, Object parameter, CultureInfo culture)'