开发者

C# WPF catch exception in subform called by winform

开发者 https://www.devze.com 2023-02-25 16:32 出处:网络
I have a WPF application that calls a winforms subform. The winform calls a WPF window using showDialog(). The WPF window contains borders that I am setting the background image of. My problem is this

I have a WPF application that calls a winforms subform. The winform calls a WPF window using showDialog(). The WPF window contains borders that I am setting the background image of. My problem is this. If an image that is being loaded has a problem, I get an ArgumentException telling me the image has an invalid metadata header. Even if I catch the error, the WPF sub window still loses focus behind the other two windows and any interaction with it that would set the dialogResult to true cause an InvalidOperationException because it doesn't register the window as having been called by showDialog().

I'm prob开发者_开发技巧ably doing something blatantly wrong. However, how should I be handling this exception, and why does the WPF sub window behave this way?

Edit: The exception seems to occur whenever I set the uri or stream source of a bitmapImage. However, placing this into a try block doesn't cause it to be caught here, it is caught in the showDialog() call.


Not trying to solve the problem but make a joke:

a WPF application that calls a winforms subform. The winform calls a WPF window using showDialog()

That is the root of all problems :D

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号