Skip to content

SizeChanged event fires when size hasn't changed #27223

@MitchBomcanhao

Description

@MitchBomcanhao

Description

I'm not entirely sure if this is a bug or not, but it feels like one, and I'd like your opinion on it.

I'm getting SizeChanged events firing for a UI element that is not being modified - its position on screen is changing as the layout recalculates itself when I resize the window, but the height/width of the element should otherwise be unchanged. when looking at the values, they appear unchanged. briefly looking into maui code (although I could be looking in the wrong place), it seems that this event may be fired when the bounding rectangle changes in some way, which includes its originating coordinates, besides the width and height.

example consecutive events firing when resizing the window vertically:

  • SizeChanged {X=0 Y=614.4000244140625 Width=700 Height=70.4000015258789}
  • SizeChanged {X=0 Y=636 Width=700 Height=70.4000015258789}

what should be happening, then?

Steps to Reproduce

  • Create a blank maui project.
  • replace the mainpage content with the one below
  • replace the relevant c# code with the one below
  • run the app and resize the window vertically
  • OBSERVE
    • the VerticalStackLayout_SizeChanged method will keep firing even though the actual size of the VerticalStackLayout hasn't changed.
    <Grid ColumnDefinitions="*,*,*">
        <Grid Grid.Column="0" RowDefinitions="Auto,*,Auto">
            <Label x:Name="Counter" Grid.Row="0" />
            <VerticalStackLayout Grid.Row="2" SizeChanged="VerticalStackLayout_SizeChanged">
                <Button Text="button 1" />
                <Button Text="button 2" />
                <Button Text="button 3" />
            </VerticalStackLayout>
        </Grid>
        <Editor x:Name="ShowSizes"
                Grid.Column="1"
                BackgroundColor="DarkBlue"
                VerticalOptions="Fill" />
        <Editor x:Name="ShowCoordinates"
                Grid.Column="2"
                BackgroundColor="DarkGoldenrod"
                VerticalOptions="Fill" />
    </Grid>
        int counter = 0;
        private void VerticalStackLayout_SizeChanged(object sender, EventArgs e)
        {
            if (sender is VerticalStackLayout ctrl)
            {
                counter++;
                this.Counter.Text = $"resized {counter} times";
                this.ShowSizes.Text = $"Width:{ctrl.Width:G17} Height:{ctrl.Height:G17}\n" + this.ShowSizes.Text;
                this.ShowCoordinates.Text = $"X:{ctrl.X} Y:{ctrl.Y} \n" + this.ShowCoordinates.Text;
            }
        }

Image

Link to public reproduction project repository

No response

Version with bug

9.0.30 SR3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    partner/syncfusionIssues / PR's with Syncfusion collaborationplatform/windowss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions