繁体   English   中英

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

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

首先,这可能是一个愚蠢的问题(您可以直接在 WPF 窗口中加载 WPF 内容),但实际上阅读完整描述以了解我为什么需要这个。

我正在开发一个 C# WPF 应用程序来模拟 Windows 丙烯酸模糊效果。 我正在使用此处的示例代码: Win32 Composition Samples

使用此代码,我能够在HwndHost上或直接在 Window 上创建丙烯酸模糊。 但这会导致 Windows 航空航天问题,这意味着我在 window 上绘制的所有控件都将出现在 AcrylicBlur(模糊)下。 像这个:

亚克力问题

亚克力内容重叠我的 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.

可能有效的解决方案

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. 但这有几个问题。

找到一种方法来托管 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM