Question

I have a list on my XAML page bind to my ViewModel. The list Show only the entries - there is no Feature to edit or update them (they are read from Server api).

In the application bar I have a button for reloading the list (sending again the request to the Server).

What must I do for this "reload Feature"?

I think about following:

  • removing the existing collection of my entries
  • firering the LoadData again

Are there any snippets for my question? What is about Memory issues because of my previous existing collection?

Was it helpful?

Solution

Something like this would work if you think your callback will be pretty light. If you think it may be heavy with a lot of items coming back then this may not be the most efficient way but would still work:

 public class YourViewModel
 {
     public ObservableCollection<YourDataType> YourCollection { get; set; } 

     public ICommand ReloadDataCommand { get; set; }

     public YourViewModel()
     {
         YourCollection = new ObservableCollection<YourDataType>();
         ReloadDataCommand = new DelegateCommand(ReloadData);
     }

     private void ReloadData()
     {
         //Get your new data;
         YourCollection = new ObservableCollection(someService.GetData());
         RaisePropertyChange("YourCollection");
         //Depending on how many items your bringing in will depend on whether its a good idea to recreate the whole collection like this. If its too big then you may be better off removing/adding these items as needed.
     }
 }

In XAML:

     <Button Content="Reload" Command="{Binding ReloadDataCommand}" />
     <List ItemsSource="{Binding YourCollection}">
       <!-- All your other list stuff -->
     </List>

Hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top