tags:

views:

24

answers:

3

I've a winforms control within a WindowsFormsHost on a WPF control. The WPF control is only visible some of the time, and when it becomes visible the contents of the winforms control have usually changed.

When the ViewModel for the WPF control changes I change the contents of the winforms control and the WPF control becomes visible.

Unfortunately, the previous contents of the winforms control is repainted, as if from a visual cache. I've run it through the debugger and I know that the winforms control is having its data updated, but it won't repaint until I re-size the program window (when a repaint is clearly triggered).

I've tried Invalidate() on the winforms control and InvalidateVisual(), InvalidateArrange() and InvalidateMeasure() on the WPF control inside the DataContextChanged event handler for the WPF control, but it seems that because the WPF control is not visible at this point (it's just about to become visible) these method calls are swallowed.

Anyone got any clever ideas on how to force a repaint of a WinFormsHost-ed winforms control immediately after the hosting WPF control becomes visible?

A: 

Did you try to invalidate the WinForms control in the IsVisibleChanged event handler ?

Thomas Levesque
Nope, but I have now and that didn't work either. I guess it's the same problem as the IsVisibleChanged handler is called in response to the Visibility changing but before it actually changes.
Jackson Pope
No, it's supposed to be triggered after the control becomes visible or hidden...
Thomas Levesque
A: 

You should be able to call Refresh() on the hosted Control as soon as you make it visible. Refresh(), as per the documentation:

Forces the control to invalidate its client area and immediately redraw itself and any child controls.

Reed Copsey
Sadly that didn't work either - because in the DataContextChanged handler the winforms control, its WindowsFormsHost and the WPF control are all collapsed - so the repaint is swallowed.
Jackson Pope
A: 

This turned out to be due to the underlying data-structure failing to notify that it had changed - nothing to do with the paint methods at all! :( Thanks for your help guys.

Jackson Pope