Its simple, you cannot add a reference to the DWM of the windows, BUT you can import it by using the DllImport (
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx[
^])
What I usually do is:
Create the following class:
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
namespace WpfApplication1
{
public static class GlassLib
{
struct MARGINS
{
public MARGINS(Thickness t)
{
Left = (int)t.Left;
Right = (int)t.Right;
Top = (int)t.Top;
Bottom = (int)t.Bottom;
}
public int Left;
public int Right;
public int Top;
public int Bottom;
}
[DllImport("dwmapi.dll", PreserveSig = false)]
static extern void DwmExtendFrameIntoClientArea(
IntPtr hwnd, ref MARGINS margins);
[DllImport("dwmapi.dll", PreserveSig = false)]
static extern bool DwmIsCompositionEnabled();
public static void ApplyGlass(this Window window)
{
try
{
if (DwmIsCompositionEnabled())
{
IntPtr hwnd =
new WindowInteropHelper(window).Handle;
if (hwnd == IntPtr.Zero)
throw new InvalidOperationException(
"The Window must be shown before extending glass.");
window.Background = Brushes.Transparent;
HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor =
Colors.Transparent;
MARGINS margins = new MARGINS(new Thickness(-1));
DwmExtendFrameIntoClientArea(hwnd, ref margins);
}
}
catch (Exception Ex)
{
throw Ex;
}
}
}
}
Then in the Window you want to add the Glass Effect you do:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
this.ApplyGlass();
}
}
Build, Run, and there you go GLASS..
Note that in order for this to work you must either have a Windows OS 6 (Vista) or greater OR handle the Exception that WILL be thrown by the ApplyGlass Method.
Hope this helps
All Best,
Raul Mainardi Neto