1

i'm stuck with airspace problem. My WPF app hosts a winform component. I want to display a popup with some "waiting-please" text during component loading and long activities. Here I get my problem: popup is correctly display but when I handle component's busy event I cannot update popup content. Here some code XAML:

<WindowsFormsHost Name="wfh" Grid.Row="1" Grid.Column="0" ></WindowsFormsHost>
<Popup x:Name="Overlay" AllowsTransparency="True" Placement="Center" 
       StaysOpen="True"
       IsOpen="True" 
       PlacementTarget="{Binding RelativeSource={RelativeSource FindAncestor,   AncestorType=Grid, AncestorLevel=1}}">
    <TextBlock Name="tbWait"  Foreground="Red" />
</Popup>

and c#:

myWinformComponent.Event => (s, e) => 
{ 
   tbWait.Text = e.IsBusy ?  "Loading..." : string.Empty;
}

I know what is the Airspace problem with WinForm and WPF but I was supposed that keep the popup always open let me display any content ove the windowformshost.

EDIT: I'm placing some breakpoints into the code behind and I see the Text property change correctly. This changes are not display into the UI.

Have you any workaround or solution? Thank you guys!

michele
  • 2,091
  • 1
  • 16
  • 24
  • 1
    possible duplicate of [Force redraw before long running operations](http://stackoverflow.com/questions/8128670/force-redraw-before-long-running-operations) – Hans Passant Sep 25 '12 at 13:01
  • @HansPassant I will try with the solution reported in the question you linked. But I'm afraid that my problem it's not a problem of UI freezing or similar that I can solve with Dispatcher or BackgroundWorker. – michele Sep 25 '12 at 13:10
  • @HansPassant The answer you linked works! Thank you! – michele Sep 25 '12 at 13:39

2 Answers2

0

According with @HansPassant comment, I can force redraw with these lines:

DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(delegate(object parameter) {
        frame.Continue = false;
        return null;
    }), null);
Dispatcher.PushFrame(frame);

Maybe it's not the most elegant solution, but it's a working patch to my issue.

michele
  • 2,091
  • 1
  • 16
  • 24
-2

Unfortunately, you can't display any WPF content over a WindowsFormsHost. I spent a long time fighting this quirk myself, until I finally gave up and rearraged the UI to make the overlay not have to be over the WinForms component.

Rob H
  • 1,840
  • 16
  • 25
  • I can display the popup over my windowformshost: my problem is that I cannot update infos on popup although properties are correctly changed in codebehind. – michele Sep 25 '12 at 13:00
  • Do you actually see the popup or do you just know that it's there based on tools? – Rob H Sep 25 '12 at 13:04
  • Well, that's surprising. :) Have you tried removing the WFH to see if the popup updates correctly without it there? – Rob H Sep 25 '12 at 13:09
  • Yes, if i simply hide the WFH the popup will update correctly. – michele Sep 25 '12 at 13:28