Skip to content

Layout measurement issue for controls in WindowDrawnDecorationsContent when IsVisible=false is applied through Window.Styles #21570

Description

@Fachep

Describe the bug

Layoutable.MeasureCore inside WindowDrawnDecorationsContent returns full size even when IsVisible is set to false via Window.Styles.

To Reproduce

Add a theme for WindowDrawnDecorations to Application.Styles

<ControlTheme x:Key="{x:Type WindowDrawnDecorations}" TargetType="WindowDrawnDecorations">
    <Setter Property="Template">
        <WindowDrawnDecorationsTemplate>
            <WindowDrawnDecorationsContent>
                <WindowDrawnDecorationsContent.Overlay>
                    <!-- Overlay: only interactive caption buttons -->
                    <ContentControl>
                        <StackPanel VerticalAlignment="Top"
                                    HorizontalAlignment="Right"
                                    Height="{TemplateBinding TitleBarHeight}"
                                    Orientation="Horizontal"
                                    Background="Black">
                            <Rectangle x:Name="A" Fill="Red" Width="30" />
                            <Rectangle x:Name="B" Fill="Green" Width="30" />
                            <Rectangle x:Name="C" Fill="Blue" Width="30" />
                        </StackPanel>
                    </ContentControl>
                </WindowDrawnDecorationsContent.Overlay>
    
            </WindowDrawnDecorationsContent>
        </WindowDrawnDecorationsTemplate>
    </Setter>
</ControlTheme>

Set IsVisibleProperty of controls inside WindowDrawnDecorationsContent via Window.Styles

<Style Selector="WindowDrawnDecorations /template/ Rectangle#B">
    <Setter Property="IsVisible" Value="False" />
</Style>

Enable client decorations for the window

<Window ...
        ExtendClientAreaToDecorationsHint="True"
        ExtendClientAreaTitleBarHeightHint="30">
    ...
</Window>
Image

Rectangle#B is hidden, but the StackPanel stills takes up a layout of three rectangles (Width: 90).

Expected behavior

StackPanel.Width should be 60 for above example

Avalonia version

12.0.4

OS

Windows

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions