kirushan
kirushan

Reputation: 508

How to populate a listview in a button Click. C# Metro app

I have a list view. I populate it from a list collection from back end. I want it to get populated when a button is clicked.

My List its global:

List<Collection> ResourceList;

ResourceList = new List<Collection>();

My button

 <AppBarButton x:Name="btnDocuments" Height="92" Width="82" Label="Documents" Click="btnDocuments_Click"> 
      <AppBarButton.Icon> 
           <BitmapIcon UriSource="Assets/doc.png"  Margin="8,5,7,7"/> 
      </AppBarButton.Icon> 
 </AppBarButton>

My Button Click.

 private void btnDocuments_Click(object sender, RoutedEventArgs e)
         {              
             ResourceList.Add(new Collection { ID = 1, Name = "hi" });       
         }

It gets populated when I call this method at the launch of the view but not inside a click event.

Can someone kindly help me do this. Any kind of help is appreciated.

Upvotes: 0

Views: 197

Answers (1)

danvy
danvy

Reputation: 2105

You might change your List<> for an ObservableCollection<>

List<Collection> ResourceList;
ResourceList = new List<Collection>();

Becomes

ObservableCollection<Collection> ResourceList;
ResourceList = new ObservableCollection<Collection>();

Upvotes: 1

Related Questions