Layout.InValidateLayout Method Xamarin forms

sonal khatri 81 Reputation points
2022-02-28T07:38:34.303+00:00

Hi,

Could anyone explain what Layout.InvalidateLayout Method does. It's being used in my project, but I am not sure what's the use of it and what does InValidateLayout() do.

It would be great if anyone could explain this with an example.

Thanks

Developer technologies .NET Xamarin
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2022-03-01T07:53:11.01+00:00

    Hello anonymous user,

    Elements invalidate themselves by invoking the InvalidateMeasure method, generally when a property of the element changes that might result in a new size of the element. The Layout class also defines an InvalidateLayout method that has a similar purpose to the InvalidateMeasure method. The InvalidateLayout method should be invoked whenever a change is made that affects how the layout positions and sizes its children.

    You could refer to the Invalidation part of this article at https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/custom#invalidation and this article at https://learn.microsoft.com/en-us/xamarin/xamarin-forms/creating-mobile-apps-xamarin-forms/summaries/chapter26#some-rules-for-coding-layouts

    About sample, you could check https://learn.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/userinterface-customlayout-wraplayout

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.