Skip to content

ZIndex changes at runtime do not trigger redraw #21277

@maxkatz6

Description

@maxkatz6

Describe the bug

Reported on the Telegram RU channel:

Changing ZIndex at runtime does not cause controls to redraw. The visual order only updates after a window resize.

To Reproduce

	<Canvas>
		<DockPanel x:Name="p1" Canvas.Left="100" Canvas.Top="100" ZIndex="2">
			<Rectangle Width="100" Height="100" Fill="Red"/>
		</DockPanel>
		
		<DockPanel x:Name="p2" Canvas.Left="150" Canvas.Top="150" ZIndex="1">
			<Rectangle Width="100" Height="100" Fill="Blue"/>
		</DockPanel>
	</Canvas>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        p1.PointerPressed += (s, a) =>
        {
            p1.ZIndex = 2;
            p2.ZIndex = 1;
            InvalidateVisual();
        };

        p2.PointerPressed += (s, a) =>
        {
            p1.ZIndex = 1;
            p2.ZIndex = 2;
            InvalidateVisual();
        };
    }
}

Pressing on the DockPanel doesn't change zindex visually, until window is resized. InvalidateVisual doesn't invalidate zindex either.

Expected behavior

No response

Avalonia version

12.0.1

OS

Windows

Additional context

GetStartedApp.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions