I am trying to bind the IsVisible
property to a StackLayout
inside a DataTemplate
and I can't make it work.
I have tried this post but in the x:Reference
it does not let me put the x:Name
of the CollectionView
.
<CollectionView x:Name="myCollectionView"
HorizontalOptions="FillAndExpand"
ItemsSource="{Binding myBookList}">
<CollectionView.ItemTemplate>
<DataTemplate x:Name="dataTemplate">
<ContentView>
<StackLayout HorizontalOptions="EndAndExpand"
IsVisible="{Binding StackIsVisible}"
Orientation="Horizontal">
<Grid>
<ImageButton Margin="0,0,25,0"
HorizontalOptions="EndAndExpand"
Source="img1"
WidthRequest="25" />
<ImageButton Source="img2"
WidthRequest="25"
HorizontalOptions="End" />
</Grid>
<ImageButton x:Name="myImageButton"
HorizontalOptions="EndAndExpand"
Source="img3"
WidthRequest="25" />
</StackLayout>
</ContentView>
</DataTemplate>
</CollectionView.ItemTemplate>
The ViewModel and the view are correctly connected since I have other Bindings working but this one does not work for me.
private bool _StackIsVisible;
public bool StackIsVisible
{
get => _StackIsVisible;
set
{
_StackIsVisible = value;
OnPropertyChanged();
}
}
public ViewModel(){
StackIsVisible=false;
}