Skip to content

Application crash when applying clip to SwipeControl #10321

@devanathan-vaithiyanathan

Description

Describe the bug

When applying a clip to the visual of a SwipeControl using ElementCompositionPreview.GetElementVisual() and Compositor.CreateGeometricClip(), the application crashes.

Note : The method works as expected when applied to ContentControl

Steps to reproduce the bug

1.Paste the below xaml code in MainWindow.xaml

    <Grid>
        <SwipeControl x:Name="swipeControl" Background="Yellow" HorizontalAlignment="Center" VerticalAlignment="Center" Width="200" Height="100">
            <SwipeControl.LeftItems>
                 <SwipeItems>
                     <SwipeItem Text="Delete" Background="Red" />
                 </SwipeItems>
            </SwipeControl.LeftItems>
            <Grid Background="LightGray">
                <TextBlock Text="Swipe Me" HorizontalAlignment="Center" VerticalAlignment="Center" />
            </Grid>
        </SwipeControl>
    </Grid>

2.Paste the below code in MainWindow.xaml.cs

public sealed partial class MainWindow : Window
{
    public MainWindow()
    {
        this.InitializeComponent();
        swipeControl.Loaded += OnSwipeControlLoaded;
    }

    private void OnSwipeControlLoaded(object sender, RoutedEventArgs e)
    {
        ApplyClip(swipeControl, 10, (float)swipeControl.Width, (float)swipeControl.Height);
    }

    private void ApplyClip(FrameworkElement element, float cornerRadius, float width, float height)
    {
        var visual = ElementCompositionPreview.GetElementVisual(element);
        var compositor = visual.Compositor;

        var geometry = compositor.CreateRoundedRectangleGeometry();
        geometry.CornerRadius = new Vector2(cornerRadius);
        geometry.Size = new Vector2(width, height);

        var geometricClip = compositor.CreateGeometricClip(geometry);

        visual.Clip = geometricClip;
    }
}

Or
Deploy the sample
WinUISwipeControlIssue.zip

Expected behavior

The clip should be applied to the SwipeControl without causing any crashes.

Screenshots

Image

NuGet package version

WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003

Windows version

Windows 10 (20H2): Build 19042

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Crashwhenever user reports a crash or app freezearea-SwipeControlbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions