I need to apply an Aero background blur to only part of a custom-shaped WPF window. The problem is that to apply the blur with DWM, I need to provide a window handle to the DwmEnableBlurBehindWindow
function.
I have been told that the WPF popup control is actually a separate window. That is good. Can I get a popup's handle to apply blur to it? If so, how?
If you want to access a control on a wpf form from another assembly you have to use the modifier attribute x:FieldModifier="public" or use the method proposed by Jean. Save this answer.
A Windows window is identified by a "window handle" ( HWND ) and is created after the CWnd object is created by a call to the Create member function of class CWnd . The window may be destroyed either by a program call or by a user's action.
HWND is a special HANDLE which points to a window object. HWND is said to be a pointer to a Window. To get any Window, its Child or Dialog box object, we need to use an HWND object. Communication between two windows is also done using HWND's.
Try this
HwndSource source = (HwndSource)HwndSource.FromVisual(myPopup)
or this but this one only works for actual Windows, but might help for future references.
IntPtr handle = new WindowInteropHelper(myWindow).Handle;
Try this:
<Popup Name="MyPop" IsOpen="True" Height="50" Width="50">
<!--or other control-->
<Rectangle/>
</Popup>
// only after MyPop.IsOpen is true
IntPtr handle = ((HwndSource)PresentationSource.FromVisual(MyPop.Child)).Handle;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With