Avalonia
Avalonia copied to clipboard
Translate transform is applied incorrectly on a DrawingBrush when display scaling is present.
Describe the bug When display scaling is for e.g. 125% , the Drawing Brush will not translate correctly when a translate transform is applied on the brush. This can be compared by applying the same transform on a control.
To Reproduce Steps to reproduce the behavior:
- Create a sample with the below code
<Grid RowDefinitions="Auto,*">
<Slider Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=views:MainWindow}, Path=Value}"/>
<Grid Grid.Row="1" x:Name="Grid">
<Grid.Background>
<DrawingBrush TileMode="Tile"
DestinationRect="0 0 15 15">
<DrawingBrush.Drawing>
<GeometryDrawing Geometry="M0,0 L0,1 0.03,1 0.03,0.03 1,0.03 1,0 Z"
Brush="Red" />
</DrawingBrush.Drawing>
</DrawingBrush>
</Grid.Background>
</Grid>
<TextBlock Text="Hello" Grid.Row="1" FontSize="16" x:Name="TextBlock"/>
</Grid>
public partial class MainWindow : Window
{
private double _value;
private readonly TranslateTransform _transform;
public MainWindow()
{
InitializeComponent();
this.AttachDevTools();
_transform = new TranslateTransform();
((DrawingBrush)Grid.Background).Transform = _transform;
TextBlock.RenderTransform = _transform;
}
public double Value
{
get => _value;
set
{
_value = value;
_transform.X = value;
((DrawingBrush)Grid.Background).Opacity = 1 - (Random.Shared.NextDouble()*0.01);
Grid.InvalidateVisual();
}
}
}
- Run the sample
- Use the slider to change the transform value
- Compare the movement of Text with the Grid when scaling is 100% vs scaling is 125%
Expected behavior The Text and Grid drawing should translate together.
Screenshots
At 100%
At 125%
Desktop (please complete the following information):
- OS: Windows 11
- Version 11 rc1.1