How do you refresh listview/EditableListViewModelBase

1 reply. Last post: October 22, 2014 4:17 AM by Hans Kristian
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
Ryan HermanMember

I set the SourceItems to my list and when I add more Items to the List, it doesn't update/refresh.   Here is the code I'm using for the viewmodel.

I had this as a ListViewModel prior but couldn't figure it out and then looked at Batchupdate to see if I could copy the code but I'm still not getting it to update :(.  I would like to use just a simple ListviewModel instead of Editable.

Not sure if I'm missing a binding.

using System.Collections.Generic;
using System.Linq;
using IncroudRadio.Custom;
using IncroudRadio.Models;
using IncroudRadio.Radio;
using Intersoft.AppFramework;
using Intersoft.Crosslight;
using Intersoft.Crosslight.ViewModels;
using System;
using Intersoft.Crosslight.Input;

namespace IncroudRadio.ViewModels
{
    public class AlbumPortalListViewModel : EditableListViewModelBase<AlbumInfo>
    {
        #region fields

        public DelegateCommand CloseCommand { get; set; }
        public DelegateCommand MusicCommand { get; set; }
        public DelegateCommand EventsCommand { get; set; }


        private string _albumName;
        private string _albumSong;
        private byte[] _albumImage;
        public List<AlbumInfo> FullAlbumInfo;

        #endregion

        #region properties

        public string AlbumNameTitle
        {
            get { return _albumName; }
            set
            {
                _albumName = value;
                OnPropertyChanged("AlbumName");
            }
        }

        public string AlbumSongTitle
        {
            get { return _albumSong; }
            set
            {
                _albumSong = value;
                OnPropertyChanged("AlbumSong");
            }
        }

        public byte[] AlbumImage
        {
            get { return _albumImage; }
            set
            {
                _albumImage = value;
                OnPropertyChanged("radioImage");
            }
        }

        #endregion

        #region Constructor

        public AlbumPortalListViewModel()
        {
            CloseCommand = new DelegateCommand(CloseView);
            MusicCommand = new DelegateCommand(ExecuteMusic);
            EventsCommand = new DelegateCommand(ExecuteEvents);

            AlbumNameTitle = "Lost very Lost";
            AlbumSongTitle = "Lost Song";
            FullAlbumInfo = new List<AlbumInfo>();
            LoadAlbumArt();
            //LoadEvents();
            SourceItems = FullAlbumInfo;

        }

        #endregion

        #region Methods
         private async void LoadAlbumArt()
        {
            var loaderService = GetService<IImageLoaderService>();
            AlbumImage = await loaderService.LoadImageAsync("http://i.telegraph.co.uk/multimedia/archive/02661/dj_2661248b.jpg", "phone.png");
        }

        private void LoadEvents()
        {
            
            FullAlbumInfo.Add(new AlbumInfo { AlbumName = "Testing", AlbumSong = "Whats Up Baby" });
            FullAlbumInfo.Add(new AlbumInfo { AlbumName = "Testing", AlbumSong = "Whats Up Baby" });
            FullAlbumInfo.Add(new AlbumInfo { AlbumName = "Testing", AlbumSong = "Whats Up Baby" });
            FullAlbumInfo.Add(new AlbumInfo { AlbumName = "Testing", AlbumSong = "Whats Up Baby" });

        }

        private void ExecuteMusic(object parameter)
        {
            IsBatchUpdating = true;
            FullAlbumInfo.Clear();
            FullAlbumInfo.Add(new AlbumInfo { AlbumName = "WORD", AlbumSong = "COOL ICE BABY" });
            FullAlbumInfo.Add(new AlbumInfo { AlbumName = "WORD", AlbumSong = "Whats Up Baby" });
            FullAlbumInfo.Add(new AlbumInfo { AlbumName = "Testing", AlbumSong = "Whats Up Baby" });
            FullAlbumInfo.Add(new AlbumInfo { AlbumName = "WORD", AlbumSong = "COOL ICE BABY" });
            var items = this.SourceItems.ToObservable();
            var updatedItem = items.ElementAt(0);
            OnDataChanged(updatedItem);
            IsBatchUpdating = false;



        }

        private void ExecuteEvents(object parameter)
        {
            IsBatchUpdating = true;
            FullAlbumInfo.Add(new AlbumInfo { AlbumName = "Testing", AlbumSong = "Whats Up Baby" });
            FullAlbumInfo.Add(new AlbumInfo { AlbumName = "Testing", AlbumSong = "Whats Up Baby" });
            FullAlbumInfo.Add(new AlbumInfo { AlbumName = "Testing", AlbumSong = "Whats Up Baby" });
            FullAlbumInfo.Add(new AlbumInfo { AlbumName = "Testing", AlbumSong = "Whats Up Baby" });
            var items = this.SourceItems.ToObservable();
            var updatedItem = items.ElementAt(0);
            OnDataChanged(updatedItem);
            IsBatchUpdating = false;

        }


        private void CloseView(object parameter)
        {
            NavigationService.Close();
        }

        protected override void OnSourceItemsChanged(ICollection<AlbumInfo> items)
        {
            Items = items;
            RefreshGroupItems();
        }

    
        #endregion
    }
}

 Binding:

#region Template Instruction

/* To use this template you need to specify the binding member path for your item as follows :
 * - DisplayMemberPath
 * - DetailMemberPath
 * - ImageMemberPath
 * 
 * You also need to replace the TViewModel placeholder for your navigation target when navigating the selected item.
 * 
 * To learn more how to use this template, see http://developer.intersoftpt.com/display/crosslight/Using+Crosslight+Item+Templates
 */

#endregion

using Intersoft.Crosslight;

namespace IncroudRadio.BindingProviders
{
    public class AlbumPortalListBindingProvider : BindingProvider
    {
        #region Constructors

        public AlbumPortalListBindingProvider()
        {
			var itemBinding = new ItemBindingDescription
			{
                DisplayMemberPath = "AlbumName",
                DetailMemberPath = "AlbumSong",
				//   ImageMemberPath = "ImageMemberPath",
				//   ImagePlaceholder = "image_placeholder.png",
			};

            
            AddBinding("TableView", BindableProperties.ItemsSourceProperty, "Items");
            AddBinding("TableView", BindableProperties.ItemTemplateBindingProperty, itemBinding, true);
            AddBinding("TableView", BindableProperties.SelectedItemProperty, "SelectedItem", BindingMode.TwoWay);
            AddBinding("EventName", BindableProperties.TextProperty, "EventName");
            AddBinding("TableView", BindableProperties.IsBatchUpdatingProperty, "IsBatchUpdating", BindingMode.TwoWay);
            AddBinding("TableView", BindableProperties.IsEditingProperty, "IsEditing", BindingMode.TwoWay);

            
            AddBinding("AlbumLogo", BindableProperties.ImageProperty, "AlbumImage");
            AddBinding("AlbumName", BindableProperties.TextProperty, "AlbumNameTitle");
            AddBinding("AlbumSong", BindableProperties.TextProperty, "AlbumSongTitle");

            AddBinding("BioButton", BindableProperties.CommandProperty, "BioCommand");
            AddBinding("EventsButton", BindableProperties.CommandProperty, "EventsCommand");
            AddBinding("MusicButton", BindableProperties.CommandProperty, "MusicCommand");
            AddBinding("CloseView", BindableProperties.CommandProperty, "CloseCommand");

        }

        #endregion
    }
}

 

All times are GMT -5. The time now is 9:53 PM.
Previous Next