在我的应用程序中,在WindowsFormsHost中添加我的控件(WF),并在窗口中添加这个主机(WPF)。
WindowsFormsHost host = new WindowsFormsHost();
host.Child = grid; //this is instance of WF control
testwindow.testSurface.Children.Add(host); // add in Window(WPF)查询:现在需要从“网格”( WF项目而不是WPF)获取" testWindow“的句柄值来捕获testWindow的图像。
我试过"grid.Parent as WinFormsAdapter",但它是内部类。我发现了下面的文章,但都显示在WPF项目中。
请有人建议我如何做到这一点吗?
谢谢,
发布于 2017-12-06 05:10:41
试着从WindowsFormsHost中获取grid。一旦你有了它,你可以试着用你自己的方式来获得WindowsFormsHost的父级。
Control parent = grid.Parent;
Reflection.Assembly adapterAssembly = GetType(WindowsFormsHost).Assembly;
Type adapterType = adapterAssembly.GetType("System.Windows.Forms.Integration.WinFormsAdapter");
object adapterParent = adapterType.InvokeMember("_host", BindingFlags.NonPublic |BindingFlags.GetField | BindingFlags.Instance, null, adapter, new object[] {});
WindowsFormsHost winHost = adapterParent as WindowsFormsHost;请注意,上面的代码是没有测试的,但它是为了帮助和希望引导您达到最终目标。
https://stackoverflow.com/questions/47666970
复制相似问题