Avalonia
Avalonia copied to clipboard
Fixed bad test for TryModifyOrCreate to call InvalidateVisual in Shape
I think there is a mistake with Shape invalidate visual, as nothing happen when I change, for example, the StrokeJoin property.
What does the pull request do?
Remove the '!' in the following test:
if (!Pen.TryModifyOrCreate(ref _strokePen, Stroke, StrokeThickness, StrokeDashArray, StrokeDashOffset, StrokeLineCap, StrokeJoin))
{
InvalidateVisual();
}
What is the current behavior?
Currently, when the Stroke properties change such as StrokeJoin, the visual is not invalidated.
What is the updated/expected behavior with this PR?
The visual of the Shape is now updated on Stroke properties change.
How was the solution implemented (if it's not obvious)?
Just negated the test on Pen.TryModifyOrCreate as visual invalidation is required when this method return True, not False:
/// <returns>If a new instance was created and visual invalidation required.</returns>
Here I create a Rectangle with StrokeJoin = Miter by default, and cycle the StrokeJoin value with a button, the rect is not updated.
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Rectangle
x:Name="rect"
Width="200"
Height="200"
Stroke="Red"
StrokeThickness="50" />
<TextBlock Text="{Binding StrokeJoin, ElementName=rect}" />
<Button x:Name="strokeJoinBtn" Content="Cycle StrokeJoin" />
</StackPanel>
It should be round here:
It become round only if I resize the window to clip the rectangle for example.
You can test this PR using the following package version. 11.1.999-cibuild0045240-beta
. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]