我想将数据(子)从我的ViewModel绑定到StackLayout .
在XAML中,我想要的是:
<StackLayout Content="{Binding MainStackLayout}"/>
无论如何如何做到这一点?
首先,StackLayout没有“Content”属性 . 现在,如果你想绑定一些内容的形式的内容
<StackLayout Children="{Binding MyChildren}"/>
您的BindingContext(您的模型)必须实现 INotifyPropertyChanged 接口,变量可以如下所示:
INotifyPropertyChanged
private List<View> _MyChildren; public List<View> MyChildren { get { return _MyChildren; } set { if (_MyChildren != value) { _MyChildren = value; OnPropertyChanged(); } } }
1 回答
首先,StackLayout没有“Content”属性 . 现在,如果你想绑定一些内容的形式的内容
您的BindingContext(您的模型)必须实现
INotifyPropertyChanged
接口,变量可以如下所示: