WPF Aero Glass Window

来源:http://www.cnblogs.com/blly/archive/2017/10/17/7683593.html
-Advertisement-
Play Games

用法 ...


  1. 用法

    1. Win7 DwmSetWindowAttribute function
    2. Win10 SetWindowCompositionAttribute
  2. 代碼
    1.   1 using System;
        2 using System.Collections.Generic;
        3 using System.Linq;
        4 using System.Runtime.InteropServices;
        5 using System.Text;
        6 using System.Threading.Tasks;
        7 using System.Windows;
        8 using System.Windows.Interop;
        9 
       10 namespace AeroWindow
       11 {
       12     internal static class NativeMethods
       13     {
       14         [DllImport("user32.dll")]
       15         internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttribData data);
       16 
       17         [StructLayout(LayoutKind.Sequential)]
       18         internal struct WindowCompositionAttribData
       19         {
       20             public WindowCompositionAttribute Attribute;
       21             public IntPtr Data;
       22             public int SizeOfData;
       23         }
       24 
       25         [StructLayout(LayoutKind.Sequential)]
       26         internal struct AccentPolicy
       27         {
       28             public AccentState AccentState;
       29             public AccentFlags AccentFlags;
       30             public int GradientColor;
       31             public int AnimationId;
       32         }
       33 
       34         [Flags]
       35         internal enum AccentFlags
       36         {
       37             // ... 
       38             DrawLeftBorder = 0x20,
       39             DrawTopBorder = 0x40,
       40             DrawRightBorder = 0x80,
       41             DrawBottomBorder = 0x100,
       42             DrawAllBorders = (DrawLeftBorder | DrawTopBorder | DrawRightBorder | DrawBottomBorder)
       43             // ... 
       44         }
       45 
       46         internal enum WindowCompositionAttribute
       47         {
       48             // ... 
       49             WCA_ACCENT_POLICY = 19
       50             // ... 
       51         }
       52 
       53         internal enum AccentState
       54         {
       55             ACCENT_DISABLED = 0,
       56             ACCENT_ENABLE_GRADIENT = 1,
       57             ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
       58             ACCENT_ENABLE_BLURBEHIND = 3,
       59             ACCENT_INVALID_STATE = 4
       60         }
       61 
       62         public static void EnableBlur(this Window window)
       63         {
       64             if (SystemParameters.HighContrast)
       65             {
       66                 return; // Blur is not useful in high contrast mode 
       67             }
       68             SetAccentPolicy(window, NativeMethods.AccentState.ACCENT_ENABLE_BLURBEHIND);
       69         }
       70 
       71 
       72         public static void DisableBlur(this Window window)
       73         {
       74             SetAccentPolicy(window, NativeMethods.AccentState.ACCENT_DISABLED);
       75         }
       76 
       77         private static void SetAccentPolicy(Window window, NativeMethods.AccentState accentState)
       78         {
       79             var windowHelper = new WindowInteropHelper(window);
       80             var accent = new NativeMethods.AccentPolicy
       81             {
       82                 AccentState = accentState,
       83                 AccentFlags = GetAccentFlagsForTaskbarPosition(),
       84                   AnimationId = 2
       85             };
       86             var accentStructSize = Marshal.SizeOf(accent);
       87             var accentPtr = Marshal.AllocHGlobal(accentStructSize);
       88             Marshal.StructureToPtr(accent, accentPtr, false);
       89             var data = new NativeMethods.WindowCompositionAttribData
       90             {
       91                 Attribute = NativeMethods.WindowCompositionAttribute.WCA_ACCENT_POLICY,
       92                 SizeOfData = accentStructSize,
       93                 Data = accentPtr
       94             };
       95             NativeMethods.SetWindowCompositionAttribute(windowHelper.Handle, ref data);
       96             Marshal.FreeHGlobal(accentPtr);
       97         }
       98 
       99         private static NativeMethods.AccentFlags GetAccentFlagsForTaskbarPosition()
      100         {
      101             return NativeMethods.AccentFlags.DrawAllBorders;
      102         }
      103     }
      104  }

       

       1  public MainWindow()
       2         {
       3             RoutedEventHandler handler = null;
       4             handler = (s, e) =>
       5             {
       6                 Loaded -= handler;
       7                 this.EnableBlur();
       8             };
       9             Loaded += handler;
      10 
      11             InitializeComponent();
      12         }
       1 <Window x:Class="AeroWindow.MainWindow"
       2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       4         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
       5         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       6         xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
       7         xmlns:local="clr-namespace:AeroWindow"
       8         mc:Ignorable="d" 
       9         Background="#44E6ECF0" 
      10         Title="MainWindow" Height="600" Width="800" >
      11     <shell:WindowChrome.WindowChrome>
      12         <shell:WindowChrome GlassFrameThickness="1" UseAeroCaptionButtons="False"  NonClientFrameEdges="None"  CornerRadius="10" CaptionHeight="600"   />
      13     </shell:WindowChrome.WindowChrome>
      14     <Grid/>
      15 </Window>

       

  3. 效果

  

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 這是本人第一次寫博客,若有什麼錯誤的地方或者不對的地方,還請各位不吝賜教!!! 一、磁碟配額的概念 由於Linux是一個多用戶管理的操作系統,而Linux預設情況下並不限制每個用戶使用磁碟空間的大小,假如某個用戶疏忽或者惡意占滿磁碟空間,將導致系統磁碟無法寫入甚至崩潰;為了保證系統磁碟的有足夠的剩餘 ...
  • 買了Bandwagon的vps,連接上預設terminal是英文的,有時沒有中文方便,所以想讓其支持中文。 主要步驟為以下兩步: 1. 安裝中文包 chinese-support: 安裝非常簡單,如是其他版本linux系統,使用相應的線上升級命令即可,如apt-get 2.修改字元編碼配置文件 可以 ...
  • 1.背景介紹 作為運維,在公司經常遇到一些機械性重覆工作要做,例如:為新機器裝系統,一臺兩台機器裝系統,可以用光碟、U盤等介質安裝,1小時也完成了,但是如果有成百台的伺服器還要用光碟、U盤去安裝,就顯得有些力不從心了。PXE技術就能很好的解決這個問題,本文將會對PXE的工作原理有所介紹,而cobbl ...
  • ubuntu16.04,Apache2,modsecurity,自定義規則,開源WAF,示例,實驗 ...
  • 僅以此篇謹記自己,以後加油 ...
  • 對於QQ截圖,肯定是早就有認識了,只是一直沒有去認真觀察這個操作的具體實現步驟。所以這裡將自己的記憶中的步驟簡單的寫一下: 習慣性用QQ或者TIM的人,一般是使用Ctrl+Alt+A 快捷鍵(熱鍵)快速實現截圖。 因為考慮到截圖模式的時候 一般只能顯示一個窗體 所以就考慮使用單例模式 在Screen ...
  • http://www.cnblogs.com/shenba/archive/2011/04/16/2018441.html ...
  • 1、列舉ASP.NET頁面之間傳值的幾種方式。 答:使用QueryString,如.../id=1;response.Redirect() 使用Session 使用Server.Transfer 使用Cookie 2、簡述private、protected、public、internal修飾符的訪問 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...