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:
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:
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.
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)'
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With