Although this question seems to be asked for multiple times, I can't seem to find the right solution, or put the pieces together, to solve the issue.
I have a CollectionView
with inside the collection view a Bindable.Stacklayout
.
The nested Stacklayout contains a Checkbox
and the visibility of that Checkbox is being set by a property of the parent list (the CollectionView) datasource.
This initially works fine on load, however, as soon as the parent property changes (which also handles the visibility of the nested stacklayout) then the UI of the nested stacklayout is not updated. The question is, how can I achieve this?
The XAML:
<CollectionView
ItemsSource="{Binding RoomsData}"
SelectionMode="None">
<CollectionView.ItemTemplate>
<DataTemplate>
<xct:Expander
x:Name="RoomExpander"
IsExpanded="{Binding IsExpanded}">
<xct:Expander.Header>
<! -- omitted code -->
</xct:Expander.Header>
<xct:Expander.Content>
<StackLayout
BindableLayout.ItemsSource="{Binding Elements}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Grid>
<!-- omitted / simplified code a bit for readability -->
<CheckBox IsVisible="{Binding RoomsData.ElementsVisible}" />
</Grid>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</xct:Expander.Content>
</xct:Expander>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Model(s):
// Main datasource
public IList<RoomModel> RoomsData
{
get { return _roomsData; }
set { SetProperty(ref _roomsData, value); }
}
public class RoomModel : ObservableObject
{
// Other properties omitted..
private bool _elementsVisible;
public bool ElementsVisible
{
get { return _elementsVisible; }
set { SetProperty(ref _elementsVisible, value); }
}
public IList<ElementModel> Elements { get; set; }
}
public class ElementModel : ObservableObject
{
// Other properties omitted..
}
*SetProperty contains the NotifyPropertyChanged logic
At a certain point the ElementsVisible
property changes from false to true or vice versa, I would then expect that the checkboxes of the nested stacklayout changes visibility, but nothing happens. Should I notify the Elements
nested datasource to make this happen?
As Jason's opinion, you have some problems for Xamarin.Forms Relative Bindings, I do one sample that you can take a look. If I change ElementsVisible, the UI will update.
The ViewModelBase is class that implementing INotifyPropertyChanged.