microsoft / microsoft/microsoft-ui-xaml
Application crash when applying clip to SwipeControl
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
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
```
```
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](https://github.com/user-attachments/files/18573610/WinUISwipeControlIssue.zip)
### Expected behavior
The clip should be applied to the SwipeControl without causing any crashes.
### Screenshots

### 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_
Contributor guide
Research direction
Deploy the linked WinUISwipeControlIssue.zip sample, or reproduce the crash using MainWindow.xaml and MainWindow.xaml.cs with SwipeControl, ElementCompositionPreview.GetElementVisual(), and Compositor.CreateGeometricClip(). Compare the behavior with ContentControl. Done means the same rounded geometric clip can be applied to SwipeControl without the application crashing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100