1和2需要Microsoft.WindowsAPICodePack.Shell.dll 和引用using System.Windows.Interop,并只能在有DwmApi.dll 版本的Windows操作系统下使用。这两种方法的共同缺点是:在启动窗体时会一闪。

一、

 [StructLayout(LayoutKind.Sequential)]
public struct MARGINS
{
public int cxLeftWidth;
public int cxRightWidth;
public int cyTopHeight;
public int cyBottomHeight;
}; [DllImport("DwmApi.dll")]
public static extern int DwmExtendFrameIntoClientArea(
IntPtr hwnd,
ref MARGINS pMarInset); private void ExtendAeroGlass(Window window)
{
try
{
// 为WPF程序获取窗口句柄
IntPtr mainWindowPtr = new WindowInteropHelper(window).Handle;
HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent; // 设置Margins
MARGINS margins = new MARGINS(); // 扩展Aero Glass
margins.cxLeftWidth = -;
margins.cxRightWidth = -;
margins.cyTopHeight = -;
margins.cyBottomHeight = -; int hr = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
if (hr < )
{
MessageBox.Show("DwmExtendFrameIntoClientArea Failed");
}
}
catch (DllNotFoundException)
{
Application.Current.MainWindow.Background = Brushes.White;
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.Background = Brushes.Transparent;
ExtendAeroGlass(this);
}

二、

[StructLayout(LayoutKind.Sequential)]
public 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;
} public class GlassHelper
{
[DllImport("dwmapi.dll", PreserveSig = false)]
static extern void DwmExtendFrameIntoClientArea(
IntPtr hWnd, ref MARGINS pMarInset);
[DllImport("dwmapi.dll", PreserveSig = false)]
static extern bool DwmIsCompositionEnabled(); public static bool ExtendGlassFrame(Window window, Thickness margin)
{
if (!DwmIsCompositionEnabled())
return false; IntPtr hwnd = new WindowInteropHelper(window).Handle;
if (hwnd == IntPtr.Zero)
throw new InvalidOperationException(
"The Window must be shown before extending glass."); // Set the background to transparent from both the WPF and Win32 perspectives
window.Background = Brushes.Transparent;
HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent; MARGINS margins = new MARGINS(margin);
DwmExtendFrameIntoClientArea(hwnd, ref margins);
return true;
}
} protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
GlassHelper.ExtendGlassFrame(this, new Thickness(-));
}

三、

这个方法 需要Microsoft.Windows.Shell.dll   没有一闪的缺陷!

 xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell"
<shell:WindowChrome.WindowChrome>
<shell:WindowChrome GlassFrameThickness="-1" ResizeBorderThickness=""
CaptionHeight="" CornerRadius="" />
</shell:WindowChrome.WindowChrome>
    <Window.Template>
<ControlTemplate TargetType="{x:Type Window}">
<Border BorderThickness="">
<DockPanel>
<Grid x:Name="WindowHeader" DockPanel.Dock="Top" Height="">
<TextBlock Text="{TemplateBinding Title}"/>
</Grid>
<ContentPresenter Margin="5,5,5,5"/>
</DockPanel>
</Border>
</ControlTemplate>
</Window.Template>

转载地址:http://blog.csdn.net/kingscrown/article/details/7771094

WPF实现毛玻璃效果的更多相关文章

  1. WPF 的毛玻璃效果

    原文:WPF 的毛玻璃效果 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/koloumi/article/details/76917519 其实很简 ...

  2. 抛砖引玉 【镜像控件】 WPF实现毛玻璃控件不要太简单

    原文:抛砖引玉 [镜像控件] WPF实现毛玻璃控件不要太简单 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Vblegend_2013/articl ...

  3. 使用CSS3制作导航条和毛玻璃效果

    导航条对于每一个Web前端攻城狮来说并不陌生,但是毛玻璃可能会相对陌生一些.简单的说,毛玻璃其实就是让图片或者背景使用相应的方法进行模糊处理.这种效果对用户来说是十分具有视觉冲击力的. 本次分享的主题 ...

  4. 解决css3毛玻璃效果(blur)有白边问题

    做一个登录页,全屏背景图毛玻璃效果,实现方法如下: HTML: <body> <div class="login-wrap"> <div class= ...

  5. Swift 之模糊效果(毛玻璃效果,虚化效果)的实现

    前言: 之前项目中有用到过Objective-C的的模糊效果,感觉很是不错,而且iOS8之后官方SDK也直接提供了可以实现毛玻璃效果的三个类:UIBlurEffect.UIVibrancyEffect ...

  6. iOS模糊效果(毛玻璃效果)的实现

    前一段时间项目中用到毛玻璃效果,那时对UIBlurEffect类和 UIVisualEffectView这两个类做了一部分了解.但当时并没有去特别的深入研究,直到项目做完后,才静下心来好好研究了一番. ...

  7. qt qml fuzzyPanel 毛玻璃效果

    毛玻璃效果,用qml来写代码真是简短,大爱qml:) [下载地址]http://download.csdn.net/detail/surfsky/8426641 [核心代码] Rectangle{ c ...

  8. CSS3中毛玻璃效果的使用方法

    今天在使用icloud的时候看到苹果icloud官网的毛玻璃效果非常赞,仔细研究了一下它的实现方式,是使用js配合background-image: -webkit-canvas的形式绘制出的毛玻璃背 ...

  9. 【CSS】梯形、平行四边形导航条与毛玻璃效果【转】

    转载出处:http://www.cnblogs.com/Uncle-Keith/p/5943158.html 代码部分有小改动. 导航条对于每一个Web前端攻城狮来说并不陌生,但是毛玻璃可能会相对陌生 ...

随机推荐

  1. BZOJ 2879 NOI2012美食节

    链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2879 CZ市为了欢迎全国各地的同学,特地举办了一场盛大的美食节.作为一个喜欢尝鲜的美食客,小M ...

  2. 阻碍android程序员发展的几个原因

    1应该少看网上的android开发相关技术帖子,一个是错误很多,表达也不清楚,很多都是拷贝来拷贝去的.二个是技术变迁快,很多都过时了,经常看android技术相关帖子,养成了一种惰性,遇到问题不是去看 ...

  3. java设计模式--结构型模式--适配器模式

    适配器模式 概述 将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 适用性 1.你想使用一个已经存在的类,而它的接口不符合你的需 ...

  4. SQL省市区三级表结构

    -- 表的结构 areaDROP TABLE  area;CREATE TABLE  area (   id int NOT NULL ,  areaID int NOT NULL,  area va ...

  5. Compiled Language vs Scripting Language

    Referrence: Blog Compiled Languages Example: C, C++, Java Source code needs to be compiled into bits ...

  6. C 本地文件夸网文件Cp操作

    1,linux平台C简单实现本地文件cp 码子及运行效果测试

  7. python海明距离 - 5IVI4I_I_60Y的日志 - 网易博客

    python海明距离 - 5IVI4I_I_60Y的日志 - 网易博客 python海明距离   2009-10-01 09:50:41|  分类: Python |  标签: |举报 |字号大中小  ...

  8. android滑动基础篇 TouchView

    效果图: 代码部分: activity类代码: package com.TouchView; import android.app.Activity; import android.os.Bundle ...

  9. hdu 5312 Sequence(数学推导+线性探查(两数相加版))

    Problem Description Today, Soda has learned a sequence whose n-th (n≥) item )+. Now he wants to know ...

  10. [Cycle.js] Hello World in Cycle.js

    Now you should have a good idea what Cycle.run does, and what the DOM Driver is. In this lesson, we ...