Click here to Skip to main content
15,886,578 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;
using System.ComponentModel.Composition;
using System.Windows;
using MediaAssistant.Controls.Dialog;
using MediaAssistant.Controls.Library;
using MediaAssistant.Controls.MessageBox;
using MediaAssistant.Controls.WaitScreen;
using MediaAssistant.Data;
using MediaAssistant.Management;
using MefBasic;
using MefBasic.Commans;
using MefBasic.Threading;
using MediaAssistant.DAL;
using MediaAssistant.DAL.Constants;
using Newtonsoft.Json.Linq;

namespace MediaAssistant.Controls.AddMovie
{
    [Export]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class AddMoviePresenter:APresenter<AddMovieView>, IDialogContentPresenter
    {
        [ImportingConstructor]
        public AddMoviePresenter(AddMovieView view) : base(view)
        {
            Movie = new Movie {Rating = 0};
            SearchIMDbCommand = new DelegateCommand(ExecuteSearchIMDb);
        }

        [Import]
        private WaitScreenPresenter WaitScreen { get; set; }

        public DelegateCommand SearchIMDbCommand { get; set; }

        private void ExecuteSearchIMDb(object obj)
        {
            WaitScreen.Show();

            var job = new Job(SearchIMDb);
            job.Store.Add(Movie);
            job.StartBlocked();

            Genres = job.Store.GetObject<string>("Genre");
            Directors = job.Store.GetObject<string>("Director");
            Writers = job.Store.GetObject<string>("Writer");
            Stars = job.Store.GetObject<string>("Actors");

            WaitScreen.Hide();
        }

        private void SearchIMDb(Job obj)
        {
            var movie = obj.Store.GetObject<Movie>();
            movie.Status = MovieStatus.Creating;
            JObject jsonObject;
            IMDBMovieScanner.ProcessMovie(movie, out jsonObject);
            obj.Store.Add((string)jsonObject.SelectToken("Genre"),"Genre");
            obj.Store.Add((string)jsonObject.SelectToken("Director"), "Director");
            obj.Store.Add((string)jsonObject.SelectToken("Writer"), "Writer");
            obj.Store.Add((string)jsonObject.SelectToken("Actors"), "Actors");
        }

        [Import]
        private IMDBMovieScanner IMDBMovieScanner { get; set; }

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

        [Import]
        private LibraryPresenter LibraryPresenter { get; set; }

        public bool OnClosing(DialogResult dialogResult)
        {
            if(dialogResult==DialogResult.Ok && string.IsNullOrWhiteSpace(Movie.Title))
            {
                Resolve<MessageBoxPresenter>().Show("Movie title cannot be empty", "Error");
                return false;
            }
            return true;
        }
        public void ShowAddMovie()
        {
            if(Resolve<IDialogPresenter>().ShowDialog("Add Movie", this)==DialogResult.Ok)
            {
                Movie.Status = MovieStatus.Pending;
                DatabaseManager.Instance.AddMovie(Movie);
                DatabaseManager.Instance.UpdateProcessingTitle(DataSource.ShowDrivesMoviesOnly);
                WaitScreen.Hide();
            }
        }

        public Movie Movie
        {
            get { return (Movie)GetValue(MovieProperty); }
            set { SetValue(MovieProperty, value); }
        }

        public static readonly DependencyProperty MovieProperty =
            DependencyProperty.Register("Movie", typeof(Movie), typeof(AddMoviePresenter), new UIPropertyMetadata(null));

        public string Genres
        {
            get { return (string)GetValue(GenresProperty); }
            set { SetValue(GenresProperty, value); }
        }

        public static readonly DependencyProperty GenresProperty =
            DependencyProperty.Register("Genres", typeof(string), typeof(AddMoviePresenter), new UIPropertyMetadata(null));


        public string Directors
        {
            get { return (string)GetValue(DirectorsProperty); }
            set { SetValue(DirectorsProperty, value); }
        }

        public static readonly DependencyProperty DirectorsProperty =
            DependencyProperty.Register("Directors", typeof(string), typeof(AddMoviePresenter), new UIPropertyMetadata(null));


        public string Writers
        {
            get { return (string)GetValue(WritersProperty); }
            set { SetValue(WritersProperty, value); }
        }

        public static readonly DependencyProperty WritersProperty =
            DependencyProperty.Register("Writers", typeof(string), typeof(AddMoviePresenter), new UIPropertyMetadata(null));


        public string Stars
        {
            get { return (string)GetValue(StarsProperty); }
            set { SetValue(StarsProperty, value); }
        }

        public static readonly DependencyProperty StarsProperty =
            DependencyProperty.Register("Stars", typeof(string), typeof(AddMoviePresenter), new UIPropertyMetadata(null));



        
    }
}

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