'Xamarin.Forms: editing (in VS) custom control's property value at runtime in XAML doesn't cause any updates

I have a custom control in Xamarin.Forms app that's described via XAML. For example, CustomControl.xaml:

<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             x:Class="Sample.CustomControl">
    <Ellipse Fill="White"
             WidthRequest="32"
             HeightRequest="32">
    </Ellipse>
</ContentView>

And corresponding CustomControl.xaml.cs:

public partial class CustomControl: ContentView
{
    public CustomControl()
    {
        InitializeComponent();
    }
}

If I use this control in my MainPage.xaml and set some of its' properties, they are applied correct at startup, but then if I try to change any of values at runtime, nothing happens.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:controls="clr-namespace:Sample;assembly=Sample"
             x:Class="Sample.MainPage">
    <StackLayout>
        <AbsoluteLayout VerticalOptions="FillAndExpand">
            <controls:CustomControl x:Name="CustomControl"
                                    AbsoluteLayout.LayoutBounds="0.5, 0.5" // <- At startup this control is positioned in center but then if I change this property at runtime layout doesn't rearrange
                                    AbsoluteLayout.LayoutFlags="PositionProportional">
            </controls:CustomControl>
        </AbsoluteLayout>
    </StackLayout>
</ContentPage>

At the same time, if I move those properties from MainPage.xaml to the root level of CustomControl.xaml.cs and change them at runtime, layout rearranges like expected:

<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             x:Class="Sample.CustomControl"
             AbsoluteLayout.LayoutBounds="0.5, 0.5" // <- If I place this property in child's XAML and change it at runtime the position of element changes
             AbsoluteLayout.LayoutFlags="PositionProportional">
    <Ellipse Fill="White"
             WidthRequest="32"
             HeightRequest="32">
    </Ellipse>
</ContentView>

Maybe this thing is related to XAML hot reload, because binding of that property works in both cases, no matter where I set property binding (at 'control' level or at 'page' level). Could someone explain, why changing property value in page XAML file at runtime doesn't cause any updates?


UPDATE 24.04.2022

I found the solution. I had to change 'Hot Reload mode' to 'Full page' in VS settings. Now during debug session every change that I make to XAML files is reflected immediately. enter image description here



Solution 1:[1]

I don't know how do you set the property value at runtime. I had done a simple and test your code. If I put the following code into a button's clicked event in the page.cs, the position of element will change when the button is clicked.

AbsoluteLayout.SetLayoutBounds(CustomControl,
new Rectangle(0.6f,
    0.8f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));

If you need more information, please check the api about the AbsoluteLayout:https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.absolutelayout?view=xamarin-forms

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Liyun Zhang - MSFT