Update AbsoluteLayout bounds in parent Page from ContentView

BacNongTienBacNongTien VNMember ✭✭

Hi all,

I have a custom control name ButtonX (actually is a ContentView which contains few labels & image). This button is placed inside an AbsoluteLayout of MainPage. When user clicks on this button, I would like to update its position or size by using AbsoluteLayout.SetLayoutBounds method. But it doesn't work. Remember that, I update the bounds in ButtonX code, not in the MainPage code.

I have no idea how to do that, could you please help me to figure out the cause?

Thanks & best regards,

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    I created a simple content view and define the button's click event there:

    public partial class ButtonX : ContentView
    {
        public ButtonX()
        {
            InitializeComponent();
        }
    
        private void Button_Clicked(object sender, EventArgs e)
        {
            AbsoluteLayout.SetLayoutBounds(this, new Rectangle(.5, 1, 100, 100));
            AbsoluteLayout.SetLayoutFlags(this, AbsoluteLayoutFlags.PositionProportional);
        }
    }
    

    Then I place this content view in the content page:

    <AbsoluteLayout>
        <local:ButtonX AbsoluteLayout.LayoutBounds="0, 0, 100, 100" AbsoluteLayout.LayoutFlags="PositionProportional"/>
    </AbsoluteLayout>
    

    This content view could be moved when I click the button:

Sign In or Register to comment.