alielie
2025-08-25 c4a3f8db90530a727ffab77c3bb5bb7d782792bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Windows;
using System.Windows.Interop;
 
namespace WPFProject.Utils
{
    public class Win32Helper
    {
        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetParent")]
        public extern static IntPtr SetParent(IntPtr childPtr, IntPtr parentPtr);
 
 
        public static IntPtr SetParentForWPF(Window child, Window parent)
        {
            WindowInteropHelper parentHelper = new WindowInteropHelper(parent);
            WindowInteropHelper childHelper = new WindowInteropHelper(child);
            child.Owner = parent;
            return SetParent(childHelper.Handle, parentHelper.Handle);
        }
    }
}