WinForms and WPF interop issue


I had to add  Windows Forms chart control to a WPF app. I hosted it using WindowsFormsHost. Things worked fine until I noticed that there is no scroll bar when I add several controls.

First, I tried to add WPF scrollbar to parent panel of WindowsFormsHost but it behaved weirdly. The scrolled WinForms controls goes out of window bound to other windows! And it is drawn on top other windows. In other words, when scrolled, it floated freely as if there is no window. 

Later, I tried to add a WinForms panel (any type of panel will work) to WindowsFormsHost and add scroll bar to the WinForms panel. It worked! Yeah!

I realized that if you need to scroll WinForms controls, you need to use WinForms scroll bar.

Note that WPF scroll bar is outside of WindowsFormsHost and the WinForms control is inside of WindowsFormsHost.  Using WPF scroll bar to scroll WinForms control is nothing short of begging for trouble.

Advertisements
WinForms and WPF interop issue

One thought on “WinForms and WPF interop issue

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s