zoukankan      html  css  js  c++  java
  • WPF Show实现ShowDialog的效果

    1、引用Win32API
    /// <summary>
    /// 禁用窗口
    /// </summary>
    /// <param name="hWnd"></param>
    /// <param name="bEnable"></param>
    /// <returns></returns>
    [DllImport("user32.dll")]
    public static extern bool EnableWindow(IntPtr hWnd, bool bEnable);//设置Enable属性
     
    2、在show之前
    Window _Window = new Window();
    DispatcherFrame frame = new DispatcherFrame(true);
    _Window.ShowActivated = true;
    IntPtr parentIntPtr = IntPtr.Zero;
    if (_Window.Owner != null)
    {
        parentIntPtr = new WindowInteropHelper(_Window.Owner).Handle;
    }
    EnableWindow(parentIntPtr, false);
    _Window.Closed += (s1, e1) =>
    {
        ComponentDispatcher.PopModal();
        frame.Continue = false;
        EnableWindow(parentIntPtr, true);
        if (_Window.Owner != null)
            _Window.Owner.Activate();
    };
    _Window.Show();
    _Window.Activate();
    try
    {
        ComponentDispatcher.PushModal();
        Dispatcher.PushFrame(frame);//show之后阻塞,以实现showdialog的效果
    }
    finally
    {
        ComponentDispatcher.PopModal();
    }
    使用这种方式,再打开window之后,只禁用弹出窗口的父窗口;而使用ShowDialog()则会禁用弹窗之外的所有窗口
  • 相关阅读:
    PAT 1025. 反转链表 (25)
    PAT 1024. 科学计数法 (20)
    PAT 1076. Forwards on Weibo (30)
    C++——cout输出小数点后指定位数
    PTA 06-图3 六度空间 (30分)
    PTA 06-图2 Saving James Bond
    PTA
    浙大PTA
    浙大PTA
    随机密码生成
  • 原文地址:https://www.cnblogs.com/JqkAman/p/12626953.html
Copyright © 2011-2022 走看看