Click here to Skip to main content
15,886,872 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.3K   5.6K   41  
WrapPanel doesn't support virtualization. But we can improve the performance by simulating virtualization.
using System.ComponentModel.Composition;
using System.Windows;
using MediaAssistant.DAL;
using MediaAssistant.Data;
using MediaAssistant.Management;
using MefBasic;
using MefBasic.Commans;
using Microsoft.Practices.Composite.Events;

namespace MediaAssistant.Controls.PlayerControl
{
    [Export]
    public class PlayerControlPresenter:APresenter<IPlayerControlView>
    {
        [ImportingConstructor]
        public PlayerControlPresenter(IPlayerControlView view, IEventAggregator eventAggregator) : base(view)
        {
            ChangeShuffleModeCommand = new DelegateCommand(ExecuteChangeShuffleMode);
            NextMusicCommand = new DelegateCommand(ExecuteNextMusic);
            PreviousMusicCommand = new DelegateCommand(ExecutePreviousMusic);
        }

        public DelegateCommand PreviousMusicCommand { get; set; }

        private void ExecutePreviousMusic(object obj)
        {
            DataSource.SelectedMusicDJ.Previous();
            RaiseCanExecuteChanged();
        }

        [Import]
        public LibraryManager LibraryManager
        {
            get { return (LibraryManager)GetValue(MyPropertyProperty); }
            set { SetValue(MyPropertyProperty, value); }
        }

        public static readonly DependencyProperty MyPropertyProperty =
            DependencyProperty.Register("MyProperty", typeof(LibraryManager), typeof(PlayerControlPresenter), new UIPropertyMetadata(null));

        
        private void RaiseCanExecuteChanged()
        {
            ChangeShuffleModeCommand.RaiseCanExecuteChanged();
            NextMusicCommand.RaiseCanExecuteChanged();
            PreviousMusicCommand.RaiseCanExecuteChanged();
        }

        public DelegateCommand NextMusicCommand { get; set; }

        private void ExecuteNextMusic(object obj)
        {
            DatabaseManager.Instance.AdvanceScore(DataSource.SelectedProfile, DataSource.PlayingMusic, -0.5);
            DataSource.SelectedMusicDJ.Next();
            RaiseCanExecuteChanged();
        }

        public DelegateCommand ChangeShuffleModeCommand { get; set; }

        private void ExecuteChangeShuffleMode(object obj)
        {
            DataSource.SelectMusicDJ(obj.ToString());
        }
       
        [Import]
        public LibraryDataSource DataSource
        {
            get { return (LibraryDataSource)GetValue(DataSourceProperty); }
            set { SetValue(DataSourceProperty, value); }
        }

        public static readonly DependencyProperty DataSourceProperty =
            DependencyProperty.Register("DataSource", typeof(LibraryDataSource), typeof(PlayerControlPresenter), 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