Click here to Skip to main content
15,881,757 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.1K   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.Management;
using MefBasic;
using MefBasic.Commans;
using Microsoft.Practices.Composite.Events;

namespace MediaAssistant.Controls.Dialog
{
    [Export(typeof(IDialogPresenter))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class DialogPresenter:APresenter<IDialogView>, IDialogPresenter
    {
        [ImportingConstructor]
        public DialogPresenter(IDialogView view) : base(view)
        {
            _view = view;
            _dialogResult = DialogResult.Cancel;
            DialogCommand = new DelegateCommand(ExecuteDialogCommand);
            _view.Closing += ViewClosing;
        }

        [Import]
        private IEventAggregator EventAggregator { get; set; }

        public string OkButtonCaption
        {
            get { return (string)GetValue(OkButtonCaptionProperty); }
            set { SetValue(OkButtonCaptionProperty, value); }
        }

        public static readonly DependencyProperty OkButtonCaptionProperty =
            DependencyProperty.Register("OkButtonCaption", typeof(string), typeof(DialogPresenter), new UIPropertyMetadata("Ok"));


        public string CancelButtonCaption
        {
            get { return (string)GetValue(CancelButtonCaptionProperty); }
            set { SetValue(CancelButtonCaptionProperty, value); }
        }

        public static readonly DependencyProperty CancelButtonCaptionProperty =
            DependencyProperty.Register("CancelButtonCaption", typeof(string), typeof(DialogPresenter), new UIPropertyMetadata("Cancel"));

        

        void ViewClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (_executingCommand) return;
            if (ContentPresenter.OnClosing(DialogResult.Cancel))
            {
                _dialogResult = DialogResult.Cancel;
            }
            else
            {
                e.Cancel = true;
            }
        }

        public DelegateCommand DialogCommand { get; set; }

        private void ExecuteDialogCommand(object obj)
        {
            _executingCommand = true;
            var dialogResult = (DialogResult)Enum.Parse(typeof(DialogResult), obj.ToString());
            if (ContentPresenter.OnClosing(dialogResult))
            {
                _dialogResult = dialogResult;
                _view.Close();
            }
            _executingCommand = false;
        }

        public static readonly DependencyProperty ContentPresenterProperty = DependencyProperty.Register(
            "ContentPresenter",
            typeof(IDialogContentPresenter),
            typeof(DialogPresenter));

        public IDialogContentPresenter ContentPresenter
        {
            get { return (IDialogContentPresenter)GetValue(ContentPresenterProperty); }
            set { SetValue(ContentPresenterProperty, value); }
        }

        public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(
            "Title",
            typeof(string),
            typeof(DialogPresenter));
        public string Title
        {
            get { return (string)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }

        private readonly IDialogView _view;
        private DialogResult _dialogResult;
        private bool _executingCommand;

        public DialogResult ShowDialog(string title, IDialogContentPresenter contentPresenter)
        {
            Title = title;
            ContentPresenter = contentPresenter;
            EventAggregator.GetEvent<BaseEvent<ShellDisabledChangedEventArgs>>().Publish(new ShellDisabledChangedEventArgs{Sender = this,Disabled = true});
            _view.ShowModal();
            EventAggregator.GetEvent<BaseEvent<ShellDisabledChangedEventArgs>>().Publish(new ShellDisabledChangedEventArgs { Sender = this, Disabled = false });
            return _dialogResult;
        }
    }
}

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