WPF Popup and WindowsFormsHost Problem
Asked Answered
E

2

6

I am hosting windowsforms control in WPF popup. Problems below:

  1. If i make StaysOpen=False i can't interact with winform control. StaysOpen to false is required because when clicked outsidet the Popup region, it should close.
  2. if i make StaysOpen=True i can interact with winform control but when i click outside the area of popup, it is not getting closed.
  3. I tried setting StaysOpen=true in MouseEnter of popup and StaysOpen=False in MouseLeave, but MouseLeave fires as and when mouse is over winform control resulting in unexpected behaviour.
  4. I even tried IsMouseCaptureWithin property of popup and found it does not work with winforms (i guess its a bug in framework).

  5. Another problem, i was trying to close popup when root main form (which is windows form) is deactivated (pressed Alt+Tab), but this event (deactivate) is fired even when i enter into one of the controls in windowshostControl in popup.

Desired Behaviour:

  1. should be able to host and interact with winform control in wpf popup.
  2. on clicking on outside the area of popup, popup should close.

Appreciate any inputs.

Thanks.

Emelinaemeline answered 27/7, 2009 at 0:41 Comment(0)
S
2

I've had many problems with the defacto-standard popups in WPF, because they are in fact a new window with their own handle. This means if you drag your application around the screen, the popup stays put (it doesn't move with your window). It also means your popup has some strange behaviors and doesn't interact with your application in ways other controls normally do.

I've created 2 decorator classes to address this problem:

PopupDecorator.cs and TimeoutPopupDecorator.cs

It's pretty simple to use:

  1. Add a namespace declaration for the new popup classes. i.e.

    xmlns:dday_wpf="clr-namespace:DDay.WPF"

  2. Surround the area you want the popup to be able to be displayed with the decorator. i.e.

    <dday_wpf:PopupDecorator x:Name="popup"> <dday_wpf:PopupDecorator.Popup> ... contents of popup go here ... </dday_wpf:PopupDecorator.Popup> ... contents of panel go here ... </dday_wpf:PopupDecorator>

It works pretty much identically to a normal Popup from that moment on.

This may not solve all your problems, but hopefully it helps.

Scotticism answered 9/12, 2009 at 17:44 Comment(1)
No problem, I've updated the links to point to the correct location now.Scotticism
P
0

This sounds a bit like my problem launching a modeless winform control from a WPF form.

Check out my question Why is my WPF textbox "kinda" readonly?.

The just being, based on what Doug said about popups being a window with its own handle, makes this applicable.

Penitentiary answered 14/12, 2009 at 13:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.