ComboBox周围出现神秘的红色边框

fla*_*ine 21 wpf xbap

我有一个WPF应用程序 - 一个XBAP - 在主页面上有一个ComboBox.当我在ComboBox中选择一个项目时,事件处理程序会重建一个集合,该集合是列表框的数据源.看起来很简单,我之前在WPF中所做的所有事情.

这是从列表中选择项目后我的下拉列表的样子:

WTF?

红色边界来自哪里?我正在从头开始构建表单,现在没有任何样式或任何内容.项目中的任何地方都没有提到"红色"字样.一旦它出现它就不会消失,并且它出现在我置于控件之上的任何东西上.

这是标记:

<ComboBox.ItemTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding Converter={StaticResource ResourceKey=DeviceInfoNameConverter}}"></TextBlock>
    </DataTemplate>
</ComboBox.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)

更多细节:

  • 这是在IE8中运行的XBAP应用程序
  • 同一页面上的其他下拉控件不会执行此操作
  • 当我尝试使用Snoop检查控制树时,边框消失
  • 转换器不是问题的根源,我已经尝试直接绑定到底层对象上的属性,但仍然会出现该框.

我对搜索到目前为止唯一的猜测是,某种默认错误模板正在应用于控件.我正在使用WIA,VS输出窗口中出现了几个COM异常,显然与ListView的数据绑定有关.控件的数据源是WIA.DeviceInfo对象,转换器只是获取下拉文本的name属性.

Sim*_*ver 30

确保您绑定的任何内容都是预期的数据类型.

当我绑定到一个decimal对象列表但我的MVVM属性类型是,我有这个'神秘的红盒子' int.如果您正在使用它们SelectedValue,请检查并仔细检查所有DisplayMemberPath,和SelectedValuePath属性 - 并确保SelectedValue在您打算使用时不使用SelectedItem.

在调试控制台中查找类似这样的绑定错误:

System.NotSupportedException: Int32Converter cannot convert from System.Decimal
Run Code Online (Sandbox Code Playgroud)

System.Windows.Data Error: 7 : ConvertBack cannot convert value '7' (type 'Decimal'). BindingExpression:Path=SharedProductHistoryFilterCriteria.FilterDays; DataItem='PricingManagerViewModel' (HashCode=19425465); target element is 'ComboBox' (Name=''); target property is 'SelectedValue' (type 'Object') NotSupportedException:'System.NotSupportedException: Int32Converter cannot convert from System.Decimal.
   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)'
Run Code Online (Sandbox Code Playgroud)

  • 修复错误背后的原因比隐藏指示更好! (3认同)
  • +1用于推荐调试控制台; 这是确定验证失败原因的最简单方法. (2认同)

dnx*_*xit -1

您选择的值是否应该不是集合的成员,而不是文件夹集合本身?即Folders.Folder.ID或类似的东西?

所以你的 CB itemsSource 将是文件夹,selectedItem 将是文件夹,selectedValue 将是名称??????

您需要将 SelectedValue 更新为集合的成员。此外,您还需要指定 ItemsSource = {Binding Path=Folders}" t。然后您需要指定 DisplayMemberPath 和 SelectedValuePath。

我会分别测试每个绑定。首先测试 IsEnabled 的绑定,方法是删除项目集合的每个绑定(如果已选择启用/禁用),然后开始测试集合的绑定。