I got the stack trace below reported from a customer. I don\'t know how to reproduce this. My WPF application has a fair number of ComboBoxes; I\'m not sure how to determine
We had the similar problem on some(didn't have time to get to precise range) versions of runtime and windows.
One of our comboboxes had following style
<ComboBox.Style>
<Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">
<Setter Property="IsDropDownOpen" Value="False"/>
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="IsDropDownOpen" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
It somehow, sometimes messed with selection highlighting and caused exception. Maybe this is helpful.
What eventually resolved this for us was to override the event causing the issue:
Protected Overrides Sub OnIsKeyboardFocusWithinChanged(e As DependencyPropertyChangedEventArgs)
Try
'GW 2015-09-20 Added this override to prevent windows 10 crashes on comboboxes within forms within datagrids
Catch ex As Exception
End Try
End Sub
Here's the code (.NET 4.5.2). Either o
isn't a ComboBox
or HighlightedElement
is null.
Personally, my first step would be to distribute the PDBs so you could get line numbers in the stack trace.
private static object CoerceIsSelectionBoxHighlighted(object o, object value)
{
ComboBox comboBox = (ComboBox)o;
return (!comboBox.IsDropDownOpen && comboBox.IsKeyboardFocusWithin) ||
(comboBox.HighlightedInfo != null && comboBox.HighlightedElement.Content == comboBox._clonedElement);
}
private ComboBoxItem HighlightedElement
{
get { return (_highlightedInfo == null) ? null : _highlightedInfo.Container as ComboBoxItem; }
}
We have a bespoke filtered combobox we made as a usercontrol that inherits from combobox. On Windows 10 machines we started to get this error for filtered comboboxes within forms on datagrid rows. We have a filtered combobox within the DataGrid.RowDetailsTemplate on a DataGrid.
To make the error go away we overrode this sub within our Filtered_Combobox class.
Protected Overrides Sub OnIsKeyboardFocusWithinChanged(e As DependencyPropertyChangedEventArgs)
Try
Catch ex As Exception
End Try
End Sub
Note: We havent put any code in the override yet because it didnt seem to do anything (despite crash the application).
I got the same error with similar code to what maiksaray shared. For me, the NullReferenceException at CoerceIsSelectionBoxHighlighted only happened on Windows 10, not on my Windows 7 dev machine. It only happened the first time the combo box was clicked to open.
In my case, I was programmatically opening and closing the combobox when the view loaded:
public MyView()
{
InitializeComponent();
Loaded += OnLoaded;
}
private void comboBox1_DropDownOpened(object sender, EventArgs e)
{
comboBox1.ItemsSource = MyClass.GetComboBoxList();
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
comboBox1.IsDropDownOpen = true;
comboBox1.IsDropDownOpen = false;
}
I was doing this as the workaround to another problem, described here: http://blog.elgaard.com/2009/09/03/wpf-making-combo-box-items-disabled-also-when-accessed-using-the-keyboard/
The error happened after DevicesComboBox_DropDownOpened completed. However, it only happened with the OnLoaded code present. If I commented out Loaded += OnLoaded, then I didn't get the error.
The solution for me was to simply avoid programmatically opening and closing the ComboBox.