Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

AbsoluteLayout Resets Child Positions

$
0
0

Is there a way around this?

If the Layout() of a child is updated that is in an AbsoluteLayout, the child's original Bounds are restored when the AbsoluteLayout's InvalidateLayout() is called by activity, such as Children.Add()

Example:
In this example, add a button to an AbsoluteLayout to a specific location, then immediately change the location. Notice how the button will always go to the original location.

                public class FormRoboScratch : ContentPage {

                    AbsoluteLayout _layoutInterface;

                _layoutInterface = new AbsoluteLayout();
                 _layoutInterface.HorizontalOptions = LayoutOptions.FillAndExpand;
                 _layoutInterface.VerticalOptions = LayoutOptions.FillAndExpand;

                  Button b = new Button();
                  b.Text = "I'm a button";

                 // Add the button to the layout at position 10, 10
                  _layoutInterface.Children.Add(b, new Point(10, 10));

                 // Now let's change that position
                  Rectangle r = ucAutoPosition.Bounds;
                  r.X = 200;
                  r.Y = 200;
                  b.Layout(r);

              Content = _layoutInterface;
}            

Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>