ListView.Footer Binding a button command issue

KevinGuevaraKevinGuevara ✭✭USUniversity ✭✭

I am trying to bind the command from a button in a footer of a listview tothe view model but for some reason my code doesnt execute when tapped.
my listview looks like

<ListView ItemsSource="{Binding Data}" ItemClickCommand="{Binding DataSelected}" > <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ViewCell.View> <StackLayout Padding="20,0,20,0"> <StackLayout Orientation="Horizontal" > <Label Text="{Binding Name }" HorizontalOptions="StartAndExpand" /> </StackLayout> </StackLayout> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.ItemTemplate> <:ListView.Footer> <StackLayout Padding="20,0,0,0" > <userControls:ButtonExt Text="Show More" Command ="{Binding Click}" /> </StackLayout> </userControls:ListViewExt.Footer> </userControls:ListViewExt>

My code behinds constructor looks like

ListViewModel viewModel; public ListPage () { InitializeComponent (); viewModel = new ListViewModel (); this.BindingContext = viewModel; }

and my command in my view model looks like

public ICommand Click { get { return new Command(() => { System.Diagnostics.Debug.WriteLine("clicked!") ; }); } }

My Click Command does not get executed when pressed. What should I do to work around this issue?

Best Answer

Answers

  • KevinGuevaraKevinGuevara ✭✭ USUniversity ✭✭

    Hey @AdamP what ended up working for me was declaring the Footer's binding context in the ListView tag like this

    <ListView Footer="{Binding}"> <ListView.FooterTemplate > <DataTemplate> <Button Command ="{Binding Click}"/> </DataTemplate> </ListView.FooterTemplate> </ListView>

    Thank you

Sign In or Register to comment.