• 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()则会禁用弹窗之外的所有窗口
  • 相关阅读:
    promethus监控JVM jar包
    ubuntu中文乱码解决办法
    IT焦躁中的赤子青年
    ftp neo4j http kafka搭建
    查看python脚本执行过程
    解决coredns-7f9c544f75-2sjs2一直处于ContainerCreating
    番茄工作法
    数据库的性能优化
    MyBatis
    CentOS下安装JDK,Tomcat,Redis,Mysql,及项目发布
  • 原文地址:https://www.cnblogs.com/JqkAman/p/12626953.html
Copyright © 2020-2023  润新知