Mysterious red border appears around ComboBox Mysterious red border appears around ComboBox wpf wpf

Mysterious red border appears around ComboBox


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


I too had the same issue, then I changed data types of both SelectedItem and ItemsSource to be double .Earlier I had list of int for ItemsSource and double for SelectedItem.It works.


Looks like it's simply a type cast issue. For my case, the SelectedIndex was bound to an Enum type property and the setter of that property was never called. I just had to explicitly cast the returned value to the correct type in both Convert and ConvertBack of my converter.