Click here to Skip to main content
15,893,668 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.6K   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 MefBasic.Commans;
using Microsoft.Practices.Composite.Events;

namespace MefBasic
{
    [Export(typeof(ShellPresenter))]
    public class ShellPresenter:APresenter<IShellView>
    {
        [ImportingConstructor]
        public ShellPresenter(IShellView view, IEventAggregator eventAggregator) : base(view)
        {
            eventAggregator.GetEvent<BaseEvent<ShellDisabledChangedEventArgs>>().Subscribe(HandleShellDisabledChangedEvent);
        }

        private void HandleShellDisabledChangedEvent(ShellDisabledChangedEventArgs obj)
        {
            Disabled = obj.Disabled;
        }


        public bool Disabled
        {
            get { return (bool)GetValue(DisabledProperty); }
            set { SetValue(DisabledProperty, value); }
        }

        public static readonly DependencyProperty DisabledProperty =
            DependencyProperty.Register("Disabled", typeof(bool), typeof(ShellPresenter), new UIPropertyMetadata(false));



        public double ShellWidth
        {
            get { return (double)GetValue(ShellWidthProperty); }
            set { SetValue(ShellWidthProperty, value); }
        }

        public static readonly DependencyProperty ShellWidthProperty =
            DependencyProperty.Register("ShellWidth", typeof(double), typeof(ShellPresenter), new UIPropertyMetadata(0.0));

        public double ShellHeight
        {
            get { return (double)GetValue(ShellHeightProperty); }
            set { SetValue(ShellHeightProperty, value); }
        }

        public static readonly DependencyProperty ShellHeightProperty =
            DependencyProperty.Register("ShellHeight", typeof(double), typeof(ShellPresenter), new UIPropertyMetadata(0.0));


        public void Initialize(Window mainWindow)
        {
            mainWindow.SizeChanged += HandleWindowSizeChanged;
            HandleWindowSizeChanged(null, null);
        }

        private void HandleWindowSizeChanged(object sender, SizeChangedEventArgs e)
        {
            if(Application.Current.MainWindow.WindowStyle==WindowStyle.None)
            {
                ShellHeight = Application.Current.MainWindow.ActualHeight;
                ShellWidth = Application.Current.MainWindow.ActualWidth;
            }
            else
            {
                ShellHeight = Application.Current.MainWindow.ActualHeight - 38;
                ShellWidth = Application.Current.MainWindow.ActualWidth - 18;
            }
        }
    }

    public class ShellDisabledChangedEventArgs:BaseEventArgs
    {
        public bool Disabled { get; set; }
    }
}

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