Hi guys,
Got a Datatemplate list that I want to toggle the buttons on and off depending on something being shown in the view model.
<ListView IsVisible="{Binding IsDisplayMenu}" IsRefreshing="{Binding IsRefreshing}" Margin="10" x:Name="ListView" ItemsSource="{Binding FoodItemList}" HasUnevenRows="True" ItemSelected="listView_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell x:Name="viewCell">
<StackLayout Margin="5" x:Name="ListViewStackLayout">
<Grid>
<...>
<StackLayout Grid.Row="0" Grid.Column="2" HorizontalOptions="End">
<Button
x:Name="addButton"
Padding="10"
Text="ADD"
CornerRadius="10"
BackgroundColor="{DynamicResource PrimaryColor}"
TextColor="{DynamicResource PrimaryButtonTextColor}"
FontSize="24"
FontFamily="FetteEng"
FontAttributes="Bold"
BindingContext="Binding Source={RelativeSource AncestorType={x:Type ViewModels:MenuPageViewModel}}, Path=AddToBasketCommand}"
CommandParameter="{Binding .}"
IsVisible="{Binding IsAddVisible}"/>
<ImageButton Source="chevronblack.png"
IsVisible="{Binding IsChevronVisible}"></ImageButton>
</StackLayout>
private void ChangeButton(string menuItemName)
{
// If the header is pizzas or flatbread.
if(menuItemName == "Pizzas" || menuItemName == "Flatbread")
{
this.IsChevronVisible = true;
this.IsAddVisible = false;
}
else
{
this.IsChevronVisible = false;
this.IsAddVisible = true;
}
}
I've set up bindings on each of the IsVisible properties to toggle them on and off but they aren't attached to the VM for some reason. Any help would be appreciated.