Xamarin形成MVVM Stacklayout子绑定

时间:2018-02-04 13:04:21

标签: c# xamarin mvvm xamarin.forms

我想将数据(子)从我的ViewModel绑定到StackLayout。

在XAML中,我想要类似的东西:

<StackLayout Content="{Binding MainStackLayout}"/>

无论如何如何做到这一点?

1 个答案:

答案 0 :(得分:1)

首先,StackLayout没有&#34;内容&#34;属性。现在,如果你想绑定一些内容,那将是

的形式
<StackLayout Children="{Binding MyChildren}"/>

您的BindingContext(您的模型)必须实现INotifyPropertyChanged接口,变量可能如下所示:

private List<View> _MyChildren;
public List<View> MyChildren
{
    get { return _MyChildren; }
    set
    {
        if (_MyChildren != value)
        {
            _MyChildren = value;
            OnPropertyChanged();
        }
    }
}