<ContentPage.BindingContext>
<vm:IdeasViewModel/>
</ContentPage.BindingContext>
<ContentPage.ToolbarItems>
<ToolbarItem Text="Logout" Command="{Binding Logoutcommand}" Clicked="Logout_Clicked"/>
</ContentPage.ToolbarItems>
<StackLayout>
<Button Command="{Binding GetIdeasCommand}"
Text="Get All Ideas"
TextColor="White"
FontSize="30"
BackgroundColor="DodgerBlue"/>
<Button Text="Add new Idea"
Clicked="Idea_Clicked"
TextColor="White"
FontSize="30"
BackgroundColor="DeepPink"/>
<Label Text=" This is listview"/>
<ListView ItemsSource="{Binding Ideas}"
HasUnevenRows="True"
ItemTapped="IdeaList_ItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="0,10">
<Label Text="List View"/>
<Label Text="{Binding Title}"
FontSize="24"
TextColor="RoyalBlue" />
<Label Text="{Binding Description}" />
<Label Text="{Binding Category}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
VieW Model-
public class IdeasViewModel: INotifyPropertyChanged
{
ApiServices _apiServices = new ApiServices();
private List<Idea> _ideas;
//public string AccessToken { get; set; }
public List<Idea> Ideas
{
get
{
return _ideas;
}
set
{
_ideas = value;
OnPropertyChanged();
}
}
public ICommand GetIdeasCommand
{
get
{
return new Command(async () =>
{
var accessToken = Settings.AccessToken;
Ideas =await _apiServices.GetIdeasAsync(accessToken);
});
}
}
public ICommand LogoutCommand
{
get
{
return new Command(() =>
{
Settings.AccessToken = "";
Settings.Username = "";
Settings.Password = "";
});
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}