问题
I am creating designer where user can drag controls to surface. Some controls in toolbar can contains broken logic and generate exceptions. When user drags broken items to surface i have unhandled exception.
I want to suppress this UI exception and show message like blend or visual studio:
workArea.Dispatcher.UnhandledException += MainContainerDispatcherUnhandledException
I can cache this exception like this:
protected void MainContainerDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
}
What i should do to suppress this message? Remove all controls from UI and shows label? or i can set some properties so WPF will ignore this exceptions? Any comments regarding this?
Thanks.
回答1:
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.
回答2:
It is necessary to hadle the event: e.Handled=true;
. DispatcherUnhandledExceptionEventArgs.Handled. Unhandled Exception Handler For WPF Applications
来源:https://stackoverflow.com/questions/10084196/how-to-suppress-ui-exceptions-in-wpf