I want to round off the edges of the transparent form, which is blurred. In some examples I have seen, the shape may be translucent (without blur), and the edges are rounded, but when I use blurring, it blurs the original size of the shape. To make it clearer, I will indent 10 pixels, and it will be seen what the problem is:
Here is the code I use:
namespace Testui { internal enum AccentState { ACCENT_DISABLED = 0, ACCENT_ENABLE_GRADIENT = 1, 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 // ... } /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class Main : System.Windows.Window { [DllImport("user32.dll")] internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data); public Main() { InitializeComponent(); CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, new ExecutedRoutedEventHandler(delegate(object sender, ExecutedRoutedEventArgs args) { this.Close(); }))); } public void DragWindow(object sender, MouseButtonEventArgs args) { DragMove(); } public void ButtonClicked(object sender, RoutedEventArgs args) { } private void Window_Loaded(object sender, RoutedEventArgs e) { EnableBlur(); } internal void EnableBlur() { var windowHelper = new WindowInteropHelper(this); var accent = new AccentPolicy { AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND }; int accentStructSize = Marshal.SizeOf(accent); var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new WindowCompositionAttributeData { Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr }; SetWindowCompositionAttribute(windowHelper.Handle, ref data); Marshal.FreeHGlobal(accentPtr); } } }
Here is the xaml code:
<Window x:Class="Testui.Main" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Main" Height="250" Width="500" Background="#0000" AllowsTransparency="True" WindowStyle="None" BorderThickness="0" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded"> <Border x:Name="brder" Margin = "0" CornerRadius="15"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="35" /> </Grid.RowDefinitions> <Border Background="CadetBlue" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="15,15,0,0" Margin="-1,0,-1,0" MouseLeftButtonDown="DragWindow"/> </Grid> </Border> I think the problem may be in this line:
var windowHelper = new WindowInteropHelper(this); This simply transfers the size of the Window, and the rounding is not taken into account.
PS I did not find any articles or links on this topic, except for one, and it is on this site (by Kamdroid). The problem was never solved, as a result.

