Ievgen
Ievgen

Reputation: 4443

How to suppress UI exceptions in wpf?

I am creating design app where users can drag and drop controls to some surface. Some controls in toolbar can contains broken logic and generate exceptions when injected to the surface. I would like to suppress some unhandled exception comming from the 3rd party controls when they are dropped.

I want to suppress this UI exception and show some kind of popup:

workArea.Dispatcher.UnhandledException += MainContainerDispatcherUnhandledException

Is is possible to handle and suppress based on the source of origin?

Thanks.

Upvotes: 0

Views: 1241

Answers (2)

IvanH
IvanH

Reputation: 5159

It is necessary to hadle the event: e.Handled=true;. DispatcherUnhandledExceptionEventArgs.Handled. Unhandled Exception Handler For WPF Applications

Upvotes: 1

Tigran
Tigran

Reputation: 62265

You can make use of AppDomain.UnhandledException and in case you recieve it, identify the control that made it happen, and

  • or show to the user a user-friendly message
  • or show some red surface (more or less like VS does)
  • or use an Adorner with animaniton (cool, but more to program)

Hope this helps.

Upvotes: 1

Related Questions