Exemplo n.º 1
0
        public MediaListViewModel(MediaList mediaList, MediaPlaybackList playbackList, CoreDispatcher dispatcher)
        {
            MediaList       = mediaList;
            PlaybackList    = playbackList;
            this.dispatcher = dispatcher;

            // Verify consistency of the lists that were passed in
            var mediaListIds    = mediaList.Select(i => i.ItemId);
            var playbackListIds = playbackList.Items.Select(
                i => (string)i.Source.CustomProperties.SingleOrDefault(
                    p => p.Key == MediaItem.MediaItemIdKey).Value);

            if (!mediaListIds.SequenceEqual(playbackListIds))
            {
                throw new ArgumentException("The passed in data model and playback model did not have the same sequence of items");
            }

            // Initialize the view model items
            initializing = true;

            foreach (var mediaItem in mediaList)
            {
                Add(new MediaItemViewModel(this, mediaItem));
            }

            initializing = false;

            // The view model supports TwoWay binding so update when the playback list item changes
            PlaybackList.CurrentItemChanged += PlaybackList_CurrentItemChanged;

            // Start where the playback list is currently at
            CurrentItemIndex = (int)PlaybackList.CurrentItemIndex;
        }