views:

629

answers:

3

Hi,

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.

+1  A: 

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:

http://www.ddaysoftware.com/Downloads/PopupDecorator.cs http://www.ddaysoftware.com/Downloads/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.

Doug
A: 

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

Check out my question http://stackoverflow.com/questions/578826/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.

Russ
A: 

Hi,

Did you find any solution for this? I exactly have the same problem. 

Your help is highly appreciated. Thanks.

Regards Kiran

Kiran