Click here to Skip to main content
15,886,518 members
Articles / Desktop Programming / WPF

Wrap Panel Virtualization

Rate me:
Please Sign up or sign in to vote.
4.95/5 (18 votes)
2 Jan 2012CPOL2 min read 53.2K   5.6K   41  
WrapPanel doesn't support virtualization. But we can improve the performance by simulating virtualization.
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Windows;
using MediaAssistant.Controls.WaitScreen;
using MediaAssistant.Data;
using MefBasic;
using MefBasic.Commans;
using MefBasic.Threading;
using MediaAssistant.DAL;
using MediaAssistant.DAL.Constants;

namespace MediaAssistant.Controls.MovieDetail
{
    [Export]
    public class MovieDetailPresenter:APresenter<MovieDetailView>
    {
        [ImportingConstructor]
        public MovieDetailPresenter(MovieDetailView view) : base(view)
        {
            SelectYearCommand = new DelegateCommand(ExecuteSelectYear);
            ShowRecommendedMoviesCommand = new DelegateCommand(ExecuteShowRecommendedMovies);
            SelectRatedLibraryItemCommand = new DelegateCommand(ExecuteSelectRatedLibraryItem);
        }

        public DelegateCommand SelectRatedLibraryItemCommand { get; set; }

        private void ExecuteSelectRatedLibraryItem(object obj)
        {
            var item = DatabaseManager.Instance.GetRatedLibraryItem(DataSource.SelectedMovie.Rated);
            if(item!=null)
            {
                DataSource.SelectedLibraryItem = item;
            }
        }

        public DelegateCommand ShowRecommendedMoviesCommand { get; set; }
        
        [Import]
        private WaitScreenPresenter WaitScreen { get; set; }
        private void ExecuteShowRecommendedMovies(object obj)
        {
            WaitScreen.Show();
            var recommendedMovies = GetRecommendedMovies();
            DataSource.SetMovieResults(recommendedMovies);
            WaitScreen.Hide();
        }

        private IEnumerable<Movie> GetRecommendedMovies()
        {
            var job = new Job(GetRecommendedMovies);
            job.Store.Add(DataSource.SelectedMovie);
            job.Store.Add(DataSource);
            job.StartBlocked();
            var recommendedMovies = job.Store.GetObject<Movie[]>();
            return recommendedMovies;
        }

        private static void GetRecommendedMovies(Job obj)
        {
            var dataSource = obj.Store.GetObject<LibraryDataSource>();
            var selectedMovie = obj.Store.GetObject<Movie>();
            var recommendedMovies = DatabaseManager.Instance.GetRecommendedMovies(selectedMovie.Title).ToArray();
            obj.Store.Add(recommendedMovies);

        }

        public DelegateCommand SelectYearCommand { get; set; }

        private void ExecuteSelectYear(object obj)
        {
            if(DataSource.SelectedMovie.Year.HasValue)
                DataSource.SelectYear(DataSource.SelectedMovie.Year.Value);
        }


        public DelegateCommand SaveMovieStateCommand { get; set; }

        

        [Import]
        public LibraryDataSource DataSource { get; set; }

        public bool Watched
        {
            get { return (bool)GetValue(WatchedProperty); }
            set { SetValue(WatchedProperty, value); }
        }

        public static readonly DependencyProperty WatchedProperty =
            DependencyProperty.Register("Watched", typeof(bool), typeof(MovieDetailPresenter), new UIPropertyMetadata(false));



        public bool IsStar
        {
            get { return (bool)GetValue(IsStarProperty); }
            set { SetValue(IsStarProperty, value); }
        }

        public static readonly DependencyProperty IsStarProperty =
            DependencyProperty.Register("IsStar", typeof(bool), typeof(MovieDetailPresenter), new UIPropertyMetadata(false));


        
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) KAZ Software Limited
Bangladesh Bangladesh
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions