首页 文章

Xamarin形成MVVM Stacklayout子绑定

提问于
浏览
0

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

在XAML中,我想要的是:

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

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

1 回答

  • 1

    首先,StackLayout没有“Content”属性 . 现在,如果你想绑定一些内容的形式的内容

    <StackLayout Children="{Binding MyChildren}"/>
    

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

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

相关问题