继承类的绑定属性

时间:2019-02-24 12:07:32

标签: c# xamarin.forms

我有三个模型。如何绑定子类的属性?

ViewModel对象_A:

private Object_A _object_A;
public Object_A Object_A
{
    get => _object_A;
    set => SetValue(ref _object_A, value);
}

Object_A类:

public class Object_A : BaseViewModel
{
    private Object_B _object_B;
    public Object_B Object_B
    {
        get => _object_B;
        set => SetValue(ref _object_B, value);
    }
}

Object_B类:

public class Object_B  : BaseViewModel
{
    private string _id = string.Empty;

    [JsonProperty("id")]
    public string Id
    {
        get => _id;
        set => SetValue(ref _id, value);
    }
}

如何访问Object_A.Object_B.Id中的属性XAML

到目前为止,我已经尝试过Text="{Binding Object_A, Path=Object_B.Id}" ...

1 个答案:

答案 0 :(得分:1)

如果您的BindingContextViewModel,则应该可以使用

Text="{Binding Object_A.Object_B.Id}"