[DllImport("user32.dll")]
  public static extern IntPtr GetAncestor(IntPtr hWnd, int flags);
 var dialog = new CustomiDalog();

            window = new Window();
            window.Content = dialog;
            window.ShowInTaskbar = false;
            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            window.SizeToContent = SizeToContent.WidthAndHeight;
            window.WindowStyle = WindowStyle.ToolWindow;
            var elementSource = HwndSource.FromVisual(rtb) as HwndSource;
            if (elementSource != null)
            {
                int GA_ROOT = 2;
                IntPtr root = GetAncestor(elementSource.Handle, GA_ROOT);
                new WindowInteropHelper(window).Owner = root;
            }
注意:如果dialog里面有事件需要注册。。先注册事件再
window.ShowDialog();

才有效果
												

wpf window set window的owner的更多相关文章

  1. WPF直接用Window.Close直接关闭窗口导致不能完全退出的问题

    前几天我在CSDN扔了一个问题,基本描述一下:写了一段这样的代码,来实现获取Control的template,却发现一个这样的问题,就是当我打开了一个window以后,手动调用Close(),窗口的确 ...

  2. C# WPF 多个window 相互覆盖的次序控制 不用topmost

    原文:C# WPF 多个window 相互覆盖的次序控制 不用topmost   WindowInteropHelper mianHanel = new WindowInteropHelper(Mai ...

  3. WPF Aero Glass Window

    原文:WPF Aero Glass Window 用法 Win7 DwmSetWindowAttribute function Win10 SetWindowCompositionAttribute ...

  4. WPF 不要给 Window 类设置变换矩阵(分析篇):System.InvalidOperationException: 转换不可逆。

    原文:WPF 不要给 Window 类设置变换矩阵(分析篇):System.InvalidOperationException: 转换不可逆. 最近总是收到一个异常 "System.Inva ...

  5. WPF 不要给 Window 类设置变换矩阵(应用篇)

    原文:WPF 不要给 Window 类设置变换矩阵(应用篇) WPF 的 Window 类是不允许设置变换矩阵的.不过,总会有小伙伴为了能够设置一下试图绕过一些验证机制. 不要试图绕过,因为你会遇到更 ...

  6. WPF 中保存 window(窗口)或者canvas成图片

    最近需要用到这个功能,搜了一下不少代码有问题 ,找到一个效果比较好的,支持多级子元素 记一下. private void button_save_window_Click(object sender, ...

  7. 关于 window.parent, window.top, window.self 详解

    在应用有frameset或者iframe的页面时,parent是父窗口,top是最顶级父窗口(有的窗口中套了好几层frameset或者iframe),self是当前窗口,opener是用open方法打 ...

  8. jquery源码中的(function(window, undefined){})(window)【转】

    (function( window, undefined ) {})(window);这个,为什么要将window和undefined作为参数传给它? (function( $, undefined ...

  9. JS 关于(function( window, undefined ) {})(window)写法的理解

    JS 关于(function( window, undefined ) {})(window)写法的理解 [网络整理] (function( window, undefined ) {})(windo ...

随机推荐

  1. c#.net循环将DataGridView中的数据赋值到Excel中,并设置样式

    Microsoft.Office.Interop.Excel.Application excel =                new Microsoft.Office.Interop.Excel ...

  2. MySQL Plugin 'InnoDB' init function returned error

    . . 在MySQL的配置文件中,设定default-table-type=InnoDB,发现MySQL无法正常的启动,错误日志中给出了如下的信息: 150210 18:11:19 mysqld_sa ...

  3. linux (RHEL) 添加和删除用户

    linux添加新用户使用 useradd -----create a new user or update default new user information 删除用户使用userdel  -- ...

  4. 8.SpringMVC参数传递

    页面参数传递到controller, 可被同名(与页面标签上的name名对应)的参数接收,用request设值,页面再取出来. 注意乱码解决办法: ①如果是get提交,则在tomcat的server. ...

  5. shell脚本监控MySQL服务是否正常

    监控MySQL服务是否正常,通常的思路为:检查3306端口是否启动,ps查看mysqld进程是否启动,命令行登录mysql执行语句返回结果,php或jsp程序检测(需要开发人员开发程序)等等: 方法1 ...

  6. Match:Blue Jeans(POJ 3080)

    DNA序列 题目大意:给你m串字符串,要你找最长的相同的连续字串 这题暴力kmp即可,注意要按字典序排序,同时,是len<3才输出no significant commonalities #in ...

  7. DP:Cow Exhibition(POJ 2184)(二维问题转01背包)

        牛的展览会 题目大意:Bessie要选一些牛参加展览,这些牛有两个属性,funness和smartness,现在要你求出怎么选,可以使所有牛的smartness和funness的最大,并且这两 ...

  8. 【leetcode】Remove Nth Node From End of List(easy)

    Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...

  9. 【leetcode】Spiral Matrix(middle)

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  10. August 25th 2016 Week 35th Thursday

    Every man dies, but not every man really lives. 每个人都会死,但不是每个人都曾经真真活过. As I become older and older, I ...