Xamarin form: BindingProperty not setting the property

58 Views Asked by At

I am having trouble on my custom control with binding property. It used to be worked when pcl project. After pulling the code out into .net standard 2.0 with latest xamarin form package, it's not working.

This is the setup i have

public static readonly BindableProperty ChildProperty = BindableProperty.Create(nameof(Child), typeof(ChildModel), typeof(ChildModel), null, BindingMode.OneWay, propertyChanging: (BindableObject bindable, object oldValue, object newValue) => {

        var a = newValue;
    });

and the property is

public ChildModel Child 
    {
        get
        { 
            return (ChildModel)GetValue(ChildProperty);
        }
        set
        {
            SetValue(ChildProperty, value);
        }
    }

I can see newValue does have the childModel data passing in the callback. The GetValue of the second set of code always return null.

        <ListView 
            Style="{StaticResource listStyle}"
            AutomationId="listChildren"
            CachingStrategy="RecycleElement"
            x:Name="childListView"   
            ItemSelected="OnItemSelected"
            ItemTapped="OnItemTapped">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <Frame HasShadow="false" Padding="{StaticResource cellPadding}">
                                <local:ExtendedFrame Style="{StaticResource cardStyle}">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*"></RowDefinition>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="{StaticResource profileGridSize}"></ColumnDefinition>
                                            <ColumnDefinition>*</ColumnDefinition>
                                        </Grid.ColumnDefinitions>

                                        <controls:CircleImage 
                                            Grid.Row="0"
                                            Grid.Column="0"
                                            Style="{StaticResource profileImageStyle}" 
                                            Source="{Binding Source}" 
                                            VerticalOptions="Center"
                                            HorizontalOptions="Center"> 
                                        </controls:CircleImage>

                                        <StackLayout Orientation="Vertical" 
                                           Grid.Row="0" 
                                           Grid.Column="1"
                                            VerticalOptions="Center"
                                            HorizontalOptions="Start">                              
                                            <Label AutomationId="aChildName" Style="{StaticResource MediumBoldFont}" x:Name="childName" Text="{Binding DisplayName}" HorizontalOptions="StartAndExpand" />
                                            <local:ChildInfoIconsView 
                                                Child="{Binding .}"
                                                VerticalOptions="Fill">
                                            </local:ChildInfoIconsView> 
                                        </StackLayout>
                                    </Grid>
                                </local:ExtendedFrame>
                            </Frame>    
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
0

There are 0 best solutions below