logeeks
logeeks

Reputation: 4979

How to override window show operation?

I have a class derived from window to show message to user. The problem is in some places in my application it is throwing an exception saying

The calling thread must be STA, because many UI components require this.

I came to know i need to introduce the Dispatcher to invoke the messagebox to get rid of the error. Since the messagebox is used in numerous locations the fastest fix i can think about is to override the show and showwindow and create and display the message box from there.

Please tell me how can i override the Show and ShowWindow events of a wpf window

Upvotes: 0

Views: 4002

Answers (1)

Gert Arnold
Gert Arnold

Reputation: 109204

I would make a static utility class that has a method (and maybe some overloads) to show this form for you. A bit like MessageBox in Windows.Forms. Within that class you can code anything that is required to show the window properly without ever having to repeat yourself.

Upvotes: 1

Related Questions