分享

WPF popup is always TOP_MOST

 louisasea 2008-12-15

Recently I have this bug inherited from my good intern that WPF <Popup/> will always be TOP_MOST in terms of z-index. The bug scenario is that when you have another application (eg. notepad.exe) going on top of my WPF application (with Popup launched), Popup will be top most even though notepad appears on top of my app. So to fix this, I'm using some old Win32 tricks :-)

[DllImport("user32", EntryPoint = "SetWindowPos")]
private static extern int SetWindowPos(IntPtr hwnd, int hwndInsertAfter, int x, int y, int cx, int cy, int wFlags); 

public class MyPopup : Popup
{
  ...
  protected override void OnOpened(EventArgs e)
  {
    IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(this.Child)).Handle;
    SetWindowPos(hwnd, -2, posX, posY, (int)this.Width, (int)this.Height, 0);
  }
}
 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多