Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带有透明模糊形状的圆角窗角_C#_Wpf_Transparent_Blur_Rounded Corners - Fatal编程技术网

C# 带有透明模糊形状的圆角窗角

C# 带有透明模糊形状的圆角窗角,c#,wpf,transparent,blur,rounded-corners,C#,Wpf,Transparent,Blur,Rounded Corners,我想用模糊把透明形状的边缘磨圆。 在我看到的一些示例中,形状可能是半透明的,然后边缘是圆形的,但是当我使用模糊时,它会模糊形状的原始大小。 为了让它更清楚,我将缩进10个像素,你将看到确切的问题是什么 以下是我使用的代码: namespace Testui { internal enum AccentState { ACCENT_DISABLED = 0, ACCENT_ENABLE_GRADIENT = 1, ACCENT_EN

我想用模糊把透明形状的边缘磨圆。 在我看到的一些示例中,形状可能是半透明的,然后边缘是圆形的,但是当我使用模糊时,它会模糊形状的原始大小。 为了让它更清楚,我将缩进10个像素,你将看到确切的问题是什么

以下是我使用的代码:

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);
        }
    }
}
进入“(此)”传输形式的大小,不考虑圆角边缘

顺便说一句,请不要给我一个Kamdroid的链接,他没有找到解决方案,对我来说也没有什么新鲜事

<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>
var windowHelper = new WindowInteropHelper(this);