Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright (c) The Avalonia Project. All rights reserved.
- // Licensed under the MIT license. See licence.md file in the project root for full license information.
- using System;
- using Avalonia;
- using Avalonia.Controls;
- using Avalonia.Markup.Xaml;
- using RenderDemo.ViewModels;
- using ReactiveUI;
- using System.Runtime.InteropServices;
- namespace RenderDemo
- {
- public class MainWindow : Window
- {
- internal enum AccentState
- {
- ACCENT_DISABLED = 1,
- ACCENT_ENABLE_GRADIENT = 0,
- ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
- ACCENT_ENABLE_BLURBEHIND = 3,
- ACCENT_INVALID_STATE = 4
- }
- [StructLayout(LayoutKind.Sequential)]
- internal struct AccentPolicy
- {
- public AccentState AccentState;
- public int AccentFlags;
- public int GradientColor;
- public int AnimationId;
- }
- [StructLayout(LayoutKind.Sequential)]
- internal struct WindowCompositionAttributeData
- {
- public WindowCompositionAttribute Attribute;
- public IntPtr Data;
- public int SizeOfData;
- }
- internal enum WindowCompositionAttribute
- {
- // ...
- WCA_ACCENT_POLICY = 19
- // ...
- }
- [DllImport("user32.dll")]
- internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
- internal void EnableBlur()
- {
- var hndl = this.PlatformImpl.Handle.Handle;
- var accent = new AccentPolicy();
- accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND;
- var accentStructSize = Marshal.SizeOf(accent);
- var accentPtr = Marshal.AllocHGlobal(accentStructSize);
- Marshal.StructureToPtr(accent, accentPtr, false);
- var data = new WindowCompositionAttributeData();
- data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY;
- data.SizeOfData = accentStructSize;
- data.Data = accentPtr;
- SetWindowCompositionAttribute(hndl, ref data);
- Marshal.FreeHGlobal(accentPtr);
- }
- public MainWindow()
- {
- this.InitializeComponent();
- this.AttachDevTools();
- var vm = new MainWindowViewModel();
- vm.WhenAnyValue(x => x.DrawDirtyRects).Subscribe(x => Renderer.DrawDirtyRects = x);
- vm.WhenAnyValue(x => x.DrawFps).Subscribe(x => Renderer.DrawFps = x);
- this.DataContext = vm;
- EnableBlur();
- }
- private void InitializeComponent()
- {
- AvaloniaXamlLoader.Load(this);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement