Mysterious red border appears around ComboBox

flatline picture flatline · Nov 11, 2010 · Viewed 19k times · Source

I have a WPF app - an XBAP - with a ComboBox on the main page. When I select an item in the ComboBox, an event handler rebuilds a collection which is the data source for a listbox. Seems like pretty simple stuff, all stuff I've done in WPF before.

This is what my dropdown looks like after selecting an item from the list:

WTF?

Where on earth did the red border come from? I am building the form from scratch, there is no styling or anything on it right now. The text "red" is not even mentioned anywhere in the project. It will not go away once it appears, and it shows up over anything that I place on top of the control.

Here's the markup:

<ComboBox.ItemTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding Converter={StaticResource ResourceKey=DeviceInfoNameConverter}}"></TextBlock>
    </DataTemplate>
</ComboBox.ItemTemplate>

Some more details:

  • This is an XBAP application running in IE8
  • Other dropdown controls on the same page are not doing this
  • The border disappears when I attempt to examine the control tree with Snoop
  • The converter is not the source of the problem, I've tried binding directly to a property on the underlying object and the box still appears.

My only guess so far from searching is that there is some sort of default error template that is being applied to the control. I'm working with WIA, and there are several COM exceptions that appear in the VS output window, apparently related to the databinding for the ListView. The data source to the control is a WIA.DeviceInfo object, the converter is just getting the name property for the dropdown text.

Answer

Simon_Weaver picture Simon_Weaver · Jul 28, 2012

Make sure whatever you're binding to exactly the expected datatype.

I had this 'mysterious red box' when I tried to bind a list of decimal objects but my MVVM property type was int. Check and double check all your SelectedValue, DisplayMemberPath, and SelectedValuePath properties if you're using them - and make sure you're not using SelectedValue when you meant to use SelectedItem.

Look in the debug console for binding errors like this :

System.NotSupportedException: Int32Converter cannot convert from System.Decimal


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)'