Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application crash when applying clip to SwipeControl #10321

Open
devanathan-vaithiyanathan opened this issue Jan 28, 2025 · 0 comments
Open

Application crash when applying clip to SwipeControl #10321

devanathan-vaithiyanathan opened this issue Jan 28, 2025 · 0 comments
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners

Comments

@devanathan-vaithiyanathan

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

1 participant