WPF SetParent子窗体不显示
把一个WPF窗体设为另一个窗体的子窗体,有人说WPF窗体用SetParent不生效,但是用SPY++看了,确实有父子关系,但子窗体就是看不见。MainWindow mmm = new MainWindow();
mmm.Show();
SetParent(new WindowInteropHelper(this).Handle, new WindowInteropHelper(mmm).Handle);
加上SetWindowLong和SetWindowPos也不行。
渴望有大神不吝赐教。 --------------------编程问答-------------------- http://www.cnblogs.com/luluping/archive/2012/02/01/2335127.html --------------------编程问答--------------------
不跟我的一样吗,我看了很多帖子了,解决不了才来问的。 --------------------编程问答-------------------- 楼主问题解决了没有呀?据说是因为WPF的子窗体是透明的,所以使用SetParent后,看不到子窗体了。我也遇到类似的问题,但是还不知道如何解决。
http://zhidao.baidu.com/question/503889204.html,这是一个相关的帖子。 --------------------编程问答--------------------
做么子我运行的没问题? --------------------编程问答--------------------
效果图
你的代码没有贴全,怀疑没有使用静态申明,这是我的代码,你只能自己对比看一下哪里不同
public class Win32Native
{
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetParent")]
public extern static IntPtr SetParent(IntPtr childPtr, IntPtr parentPtr);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
//这里照搬你的
MainWindow mmm = new MainWindow();
mmm.Show();
Win32Native.SetParent(new WindowInteropHelper(this).Handle, new WindowInteropHelper(mmm).Handle);
}
补充:.NET技术 , C#