简体   繁体   English

是否可以在 HwndHost 中托管 WPF 页面?

[英]Is it possible to Host a WPF Page in HwndHost?

First of all this might feel as a stupid Question (You could have loaded WPF content directly in a WPF window), but actually read the full description to know why I need this.首先,这可能是一个愚蠢的问题(您可以直接在 WPF 窗口中加载 WPF 内容),但实际上阅读完整描述以了解我为什么需要这个。

I am developing a C# WPF Application to Emulate Windows Acrylic Blur Effect.我正在开发一个 C# WPF 应用程序来模拟 Windows 丙烯酸模糊效果。 I am using sample code from here: Win32 Composition Samples .我正在使用此处的示例代码: Win32 Composition Samples

With this code I was able to create the acrylic blur on an HwndHost or Directly on the Window.使用此代码,我能够在HwndHost上或直接在 Window 上创建丙烯酸模糊。 But this causes the Windows Aerospace Issue which means all the controls I draw on the window will appear under the AcrylicBlur (Blurred).但这会导致 Windows 航空航天问题,这意味着我在 window 上绘制的所有控件都将出现在 AcrylicBlur(模糊)下。 Like this one:像这个:

亚克力问题

Acrylic Content Overlapping My WPF Button亚克力内容重叠我的 WPF 按钮

So I decided to create a window with acrylic effect and create a HwndHost as the child of that window so that I could overlap the WPF Content on top of the Acrylic Blur so that the WPF Controls Won't Get Blurred Out. So I decided to create a window with acrylic effect and create a HwndHost as the child of that window so that I could overlap the WPF Content on top of the Acrylic Blur so that the WPF Controls Won't Get Blurred Out.

Solution That Might Work可能有效的解决方案

There is One more Concept that I can try out, is to create two windows one with the acrylic and one with the WPF and share there WM_POSITIONCHANGED Message for both window which cause the windows to move and resize equally. There is One more Concept that I can try out, is to create two windows one with the acrylic and one with the WPF and share there WM_POSITIONCHANGED Message for both window which cause the windows to move and resize equally. But this have several issues.但这有几个问题。

Find a way to Host WPF Page, instead of using HwndHost i used HwndSource.找到一种方法来托管 WPF 页面,而不是使用 HwndHost,我使用了 HwndSource。

HwndSourceParameters param = new HwndSourceParameters("Host");
param.PositionX = 10;
param.PositionY = 10;
param.Width = 500;
param.Height = 500;
param.ExtendedWindowStyle +=0x00200000;  //This style creates a transparent window
param.WindowStyle = 0x10000000;
    
HwndSource src = new HwndSource(param);
src.SizeToContent = SizeToContent.WidthAndHeight;
src.CompositionTarget.BackgroundColor = Colors.Transparent;
src.RootVisual = new Page1(); //Your Page Here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以通过HwndHost控件绘制WPF控件? - Is it possible to draw WPF control over HwndHost control? 在WPF窗口中嵌入win32窗口,没有HwndHost - Embed win32 window in WPF window, without HwndHost 使用 HwndHost 在 WPF 内部托管外部 window 的正确方法 - Proper way of hosting an external window inside WPF using HwndHost WPF 中的死锁:如何不阻塞 HwndHost.BuildWindowCore 中的 GUI 线程? - Deadlock in WPF: How to not block the GUI thread in HwndHost.BuildWindowCore? 使用HwndHost取消同步WPF应用程序中嵌入的Unity窗口的刷新 - Desynchronize refresh of a Unity window embedded in a WPF application with HwndHost 在C#WPF中实现HwndHost以处理MouseMove和MouseWheel - Implement HwndHost to handle MouseMove and MouseWheel in C# WPF WPF是否可以从另一个线程中的一个线程托管控件? - WPF Is it possible to host a control from one thread in another? WPF应用程序,使用HwndHost托管exe,childapp关闭,获取无效的Windows处理异常 - WPF app, hosting exe with HwndHost, childapp closes itself, get invalid windows handle exception 如何让 CefSharp.Wpf.HwndHost 打开触摸键盘 - How can I make CefSharp.Wpf.HwndHost open the touch keyboard 是否可以通过容器/包装器在WPF表单中托管WinForm表单? - Is it possible to host a WinForm form within a WPF Form via a container/wrapper?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM