Skip to content

AcrylicView weird behavior with Clip #8

@JoaoCarlosBessa

Description

@JoaoCarlosBessa

I was using MaterialFrame with AcrylicBlur and I needed to clip part of its content, but due to not being able to change the color of the blur I'm trying to use AcrylicView instead, but for some reason Clip isn't working as intended can anyone help me out? I also tested using just the circle, but instead of cutting out the are like on the MaterialFrame, on the AcrylicView it just displays the content.

HomePage.xaml:

<acrylic:AcrylicView Grid.Row="2"
                     x:Name="acrylicView"
                     HorizontalOptions="Fill"
                     VerticalOptions="Fill"
                     TintColor="#022C0F"
                     TintOpacity="1"/>

<sharpnado:MaterialFrame Grid.Row="2"
                         ZIndex="1"
                         x:Name="myMaterialFrame"
                         HorizontalOptions="Fill"
                         VerticalOptions="Fill"
                         MaterialTheme="AcrylicBlur"
                         MaterialBlurStyle="Light"
                         BackgroundColor="Transparent"/>

HomePage.xaml.cs:

protected override void OnSizeAllocated(double width, double height)
{
    base.OnSizeAllocated(width, height);

    //This works
    if (myMaterialFrame != null)
    {
        var clip = new MaterialFrameClip { Width = width };
        myMaterialFrame.Clip = clip.CreateClip();
    }

    //This doesn't work
    if (acrylicView != null)
    {
        var clip = new MaterialFrameClip { Width = width };
        acrylicView.Clip = clip.CreateClip();
    }
}

MaterialFrameClip.cs:

using Microsoft.Maui.Controls.Shapes;
using Microsoft.Maui.Graphics;
using System.Diagnostics;

namespace LacosLiterarios
{

    public class MaterialFrameClip
    {
        public double Width { get; set; }
        private const double FrameHeight = 60;
        private const double ButtonRadius = 30;
        private const double ButtonTranslationY = -10;
        private const double CutoutRadius = 35; // Circle radius

        public Geometry CreateClip()
        {
            double centerX = Width / 2; // Button center (horizontal alignment)
            double centerY = ButtonRadius + ButtonTranslationY; // Button center (vertical alignment)

            var pathFigureCollection = new PathFigureCollection();

            // Outer frame shape
            var rectFigure = new PathFigure
            {
                StartPoint = new Point(0, 0),
                IsClosed = true,
                Segments =
        {
            new LineSegment(new Point(Width, 0)),
            new LineSegment(new Point(Width, FrameHeight)),
            new LineSegment(new Point(0, FrameHeight)),
            new LineSegment(new Point(0, 0))
        }
            };

            pathFigureCollection.Add(rectFigure);

            // Full Circle Cutout
            var circleFigure = new PathFigure
            {
                StartPoint = new Point(centerX - CutoutRadius, centerY), // Leftmost point of the circle
                IsClosed = true,
                Segments =
        {
            new ArcSegment
            {
                Point = new Point(centerX + CutoutRadius, centerY), // Rightmost point of the circle
                Size = new Size(CutoutRadius, CutoutRadius),
                SweepDirection = SweepDirection.Clockwise,
                IsLargeArc = true // First half of the circle
            },
            new ArcSegment
            {
                Point = new Point(centerX - CutoutRadius, centerY), // Back to starting point
                Size = new Size(CutoutRadius, CutoutRadius),
                SweepDirection = SweepDirection.Clockwise,
                IsLargeArc = true // Second half of the circle
            }
        }
            };

            pathFigureCollection.Add(circleFigure);

            return new PathGeometry { Figures = pathFigureCollection };
        }

    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions