簡體   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