-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Describe the bug
I use the ClipBorder
control in various control styles in my app to allow for rounded corners. However after doing this I noticed that some of the controls which use it start experiencing rendering issues (rounded corners not applying, background color not changing when it should etc.) when there are too many of them in total.
After a lot of experimenting I narrowed it down to the ClipBorder
control causing it if there are too many in use at once. It appears to be specifically this line of code causing it, so it's somehow related to the clip being set.
Steps to reproduce
The issue can easily be reproduced with this XAML:
<ScrollViewer>
<ItemsControl ItemsSource="{Binding Source={x:Static local:MainWindow.Items}}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<mah:ClipBorder CornerRadius="20" Width="64" Height="64" Margin="2">
<Border Background="Red">
<TextBlock Text="{Binding}"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Border>
</mah:ClipBorder>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
and then a static property like this for the items to bind to:
public static int[] Items => Enumerable.Range(0, 1000).ToArray();
This will display a big list of red squares which should be rounded. However as you will notice it breaks after rendering 145 of them.
It's not only the rounded corners that break, but other things too. For example say we made it so the color of the squares should change from red to green on mouse over:
<ScrollViewer>
<ItemsControl ItemsSource="{Binding Source={x:Static local:MainWindow.Items}}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<mah:ClipBorder CornerRadius="20" Width="64" Height="64" Margin="2">
<Border>
<Border.Style>
<Style TargetType="{x:Type Border}">
<Setter Property="Background" Value="Red" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Green" />
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<TextBlock Text="{Binding}"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Border>
</mah:ClipBorder>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
Now this works on all squares up to 145 where this also breaks.
Environment
MahApps.Metro version: v2.4.10
Windows build number: Win11 23H2
Visual Studio: 2022 17.11.5
Target Framework: .NET Framework 4.7.2