xamarin形式:绑定对象为null

时间:2018-12-11 04:40:37

标签: c# forms xamarin binding

从下面的xaml中,从ChildInfoIconsView下的ListView-DataTemplate提取,我将{Binding。}传递给Child属性。

我希望Child属性将项目传递给它,但是Child为空。这是将项目的值传递给自定义控件的方法。

                                                                                                       *             

        <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>

代码:

    public static readonly BindableProperty ChildProperty = BindableProperty.Create(nameof(Child), typeof(ChildModel), typeof(ChildModel), null, BindingMode.OneWay, null);

    public ChildModel Child
            {
                get
                {
                    var a = (ChildModel)GetValue(ChildProperty);
                    //a is null.
                    return (ChildModel)GetValue(ChildProperty);
                }
                set
                {
                    SetValue(ChildProperty, value);
                }
            }

0 个答案:

没有答案