Martin Zbořil
Martin Zbořil

Reputation: 1

Xamarin forms MVVM Stacklayout children binding

I want to binding data(children) from my ViewModel to StackLayout.

In XAML I want something like:

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

Is there anyway how to make this?

Upvotes: 0

Views: 1468

Answers (1)

Nick Kovalsky
Nick Kovalsky

Reputation: 6452

First of all, a StackLayout has no "Content" property. Now if you want to bind some content inside that would be in form of

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

Your whatever BindingContext (your model) must implement the INotifyPropertyChanged interface and the variable can look like:

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

Upvotes: 1

Related Questions