Click here to Skip to main content
15,892,674 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.Text.RegularExpressions;
using System.Windows;
using MediaAssistant.Controls.Dialog;
using MediaAssistant.Controls.WaitScreen;
using MediaAssistant.Helper;
using MefBasic;
using MediaAssistant.DAL.Helper;

namespace MediaAssistant.Controls.SendFeedback
{
    [Export]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class SendFeedbackPresenter:APresenter<SendFeedbackView>, IDialogContentPresenter
    {
        [ImportingConstructor]
        public SendFeedbackPresenter(SendFeedbackView view) : base(view)
        {
        }

        public bool OnClosing(DialogResult dialogResult)
        {
            if(dialogResult==DialogResult.Ok)
            {
                if(AllowContact)
                {
                    if(string.IsNullOrWhiteSpace(FromEmailAddress))
                    {
                        System.Windows.MessageBox.Show(
                            "To contact you, we need your email address. Please enter your email address.",
                            "Empty Email Address", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return false;
                    }
                    if (!Regex.IsMatch(FromEmailAddress, @"^([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})$"))
                    {
                        System.Windows.MessageBox.Show(
                            "The email address you entered is invalid. Please enter a valid email address.",
                            "Invalid Email Address", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return false;
                    }
                    if(string.IsNullOrWhiteSpace(Subject) && CrashBugMessageVisibility==Visibility.Collapsed)
                    {
                        System.Windows.MessageBox.Show(
                            "Please enter the subject of your feedback",
                            "Empty Subject", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return false;
                    }
                }
            }
            return true;
        }


        public bool AllowContact
        {
            get { return (bool)GetValue(AllowContactProperty); }
            set { SetValue(AllowContactProperty, value); }
        }

        public static readonly DependencyProperty AllowContactProperty =
            DependencyProperty.Register("AllowContact", typeof(bool), typeof(SendFeedbackPresenter), new UIPropertyMetadata(true));

        public void SendException(Exception exception)
        {
            var messageBox = Resolve<IDialogPresenter>();
            CrashBugMessageVisibility = Visibility.Visible;
            messageBox.OkButtonCaption = "Send";
            Subject = string.Format("Exception \"{0}\" at Media Assistant {1}", exception.Message, SystemHelper.GetVersion());
            FromEmailAddress = RegistryHelper.FromEmailAddress;

            if (messageBox.ShowDialog("Send Crash Report", this) != DialogResult.Ok) return;

            var messageBody = string.Format("Media Assistant Team,\r\nException \"{0}\" occurred at Media Assistant {1}\r\n\r\n", exception.Message, SystemHelper.GetVersion()); ;
            if(AllowContact)
            {
                messageBody += string.Format("Please contact me about this report at {0}\r\n\r\n", FromEmailAddress);
            }
            messageBody += string.Format("Exception details\r\n{0}", exception);
            messageBody += string.Format("User's Comment\r\n{0}", Message);
            Resolve<WaitScreenPresenter>().Show();
            EMailHelper.Send(FromEmailAddress,Subject, messageBody);
            RegistryHelper.FromEmailAddress = FromEmailAddress;
            Resolve<WaitScreenPresenter>().Hide();
        }

        public void SendFeedback()
        {
            var messageBox = Resolve<IDialogPresenter>();
            messageBox.OkButtonCaption = "Send";
            FromEmailAddress = RegistryHelper.FromEmailAddress;
            CrashBugMessageVisibility = Visibility.Collapsed;
            
            if (messageBox.ShowDialog("Send Feedback", this) != DialogResult.Ok) return;

            var messageBody = string.Format("Media Assistant Team, Feedback message for Media Assistant {0}\r\n\r\n", SystemHelper.GetVersion()); ;
            if (AllowContact)
            {
                messageBody += string.Format("Please contact me about this report at {0}\r\n\r\n",FromEmailAddress);
            }
            messageBody += string.Format("User's Comment\r\n{0}", Message);
            var subject = string.Format("Feedback for Media Assistant {0} - {1}",SystemHelper.GetVersion(), Subject);
            Resolve<WaitScreenPresenter>().Show();
            EMailHelper.Send(FromEmailAddress, subject, messageBody);
            RegistryHelper.FromEmailAddress = FromEmailAddress;
            Resolve<WaitScreenPresenter>().Hide();
        }

        public Visibility CrashBugMessageVisibility
        {
            get { return (Visibility)GetValue(CrashBugMessageVisibilityProperty); }
            set { SetValue(CrashBugMessageVisibilityProperty, value); }
        }

        public static readonly DependencyProperty CrashBugMessageVisibilityProperty =
            DependencyProperty.Register("CrashBugMessageVisibility", typeof(Visibility), typeof(SendFeedbackPresenter), new UIPropertyMetadata(Visibility.Collapsed));

        public string FromEmailAddress
        {
            get { return (string)GetValue(FromEmailAddressProperty); }
            set { SetValue(FromEmailAddressProperty, value); }
        }

        public static readonly DependencyProperty FromEmailAddressProperty =
            DependencyProperty.Register("FromEmailAddress", typeof(string), typeof(SendFeedbackPresenter), new UIPropertyMetadata(string.Empty));

        public string Subject
        {
            get { return (string)GetValue(SubjectProperty); }
            set { SetValue(SubjectProperty, value); }
        }

        public static readonly DependencyProperty SubjectProperty =
            DependencyProperty.Register("Subject", typeof(string), typeof(SendFeedbackPresenter), new UIPropertyMetadata(string.Empty));

        public string Message
        {
            get { return (string)GetValue(MessageProperty); }
            set { SetValue(MessageProperty, value); }
        }

        public static readonly DependencyProperty MessageProperty =
            DependencyProperty.Register("Message", typeof(string), typeof(SendFeedbackPresenter), new UIPropertyMetadata(string.Empty));


    }
}

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