Given a WPF Core/Framework application. Unhandled Exceptions should be caught by some UnhandledException
event.
TaskScheduler.UnobservedTaskException += (s, e) => Debugger.Break();
AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => Debugger.Break();
Dispatcher.UnhandledException += (sender, args) => Debugger.Break();
DispatcherUnhandledException += (sender, eventArgs) => Debugger.Break();
Given is an ObservableCollection<TItem>
collection presented by a combobox.
The collection also fires ItemPropertyChanged
events.
Collection.CollectionChanged += ItemsCollectionChanged;
public event PropertyChangedEventHandler PropertyItemChanged = delegate { };
private void ItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.OldItems != null)
{
foreach (INotifyPropertyChanged item in e.OldItems)
item.PropertyChanged -= ItemPropertyChanged;
}
if (e.NewItems != null)
{
foreach (INotifyPropertyChanged item in e.NewItems)
item.PropertyChanged += ItemPropertyChanged;
}
}
The issue was I didn't implement
private void ItemPropertyChanged(object sender, PropertyChangedEventArgs e)
{
throw new NotImplementedException("ToDo");
// done later PropertyItemChanged(sender, e);
}
When I change the collection item property from code behind/view model like this
ComboBoxCatalog.Collection.First().IsChecked = true;
everything is fine. The debugger stops on some UnhandledException
.
Now when I change an property by combobox:
<ComboBox ItemsSource="{Binding ComboBoxCatalog.Collection, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
<ComboBox.ItemTemplate>
<DataTemplate DataType="{x:Type local:CheckboxItem}">
<CheckBox Content="{Binding IsChecked}" IsChecked="{Binding IsChecked}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
None of these UnhandledException
are fired. Only FirstChanceException
are fired.
I have implemented a full working demo on Github: https://github.com/LwServices/WpfAppExceptionDemo
What need to be done that the exception will fire UnhandledException
?
Update: I get the same behavior on .NET Core 3.1 and .NET Framework 4.7.2