Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

Translate transform is applied incorrectly on a DrawingBrush when display scaling is present.

Open ijsankar opened this issue 1 year ago • 0 comments

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:

  1. 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();
            }
        }
    }
  1. Run the sample
  2. Use the slider to change the transform value
  3. 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% image image At 125% image image

Desktop (please complete the following information):

  • OS: Windows 11
  • Version 11 rc1.1

ijsankar avatar Jun 29 '23 12:06 ijsankar