我有一个组合框,其中包含我尝试绑定到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>
Run Code Online (Sandbox Code Playgroud)
这是我的问题:当我运行应用程序时,组合项目加载正常.但是当我从列表中选择一个项目时,我在"输出"窗口中收到此错误:
Int32Converter cannot convert from System.Windows.Controls.ComboBoxItem.
Run Code Online (Sandbox Code Playgroud)
窗口中的其他数据绑定工作正常.完整的错误消息将在下面重新打印.
什么是告诉我的错误消息,我该如何解决这个问题?在此先感谢您的帮助.
完整的错误消息:
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, …Run Code Online (Sandbox Code Playgroud)