Ejemplo n.º 1
0
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object</param>
        /// <returns>true if the current object is equal to the other parameter; otherwise, false.</returns>
        public bool Equals(LabelledValue <T> other)
        {
            if (Object.ReferenceEquals(this, other))
            {
                return(true);
            }
            if (Object.ReferenceEquals(other, null))
            {
                return(false);
            }

            return(this.Label == other.Label && EqualityComparer <T> .Default.Equals(this.Value, other.Value));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Setup the MessageBoxViewModel with the information it needs
        /// </summary>
        /// <param name="messageBoxText">A <see cref="System.String"/> that specifies the text to display.</param>
        /// <param name="caption">A <see cref="System.String"/> that specifies the title bar caption to display.</param>
        /// <param name="buttons">A <see cref="System.Windows.MessageBoxButton"/> value that specifies which button or buttons to display.</param>
        /// <param name="icon">A <see cref="System.Windows.MessageBoxImage"/> value that specifies the icon to display.</param>
        /// <param name="defaultResult">A <see cref="System.Windows.MessageBoxResult"/> value that specifies the default result of the message box.</param>
        /// <param name="cancelResult">A <see cref="System.Windows.MessageBoxResult"/> value that specifies the cancel result of the message box</param>
        /// <param name="buttonLabels">A dictionary specifying the button labels, if desirable</param>
        /// <param name="flowDirection">The <see cref="System.Windows.FlowDirection"/> to use, overrides the <see cref="MessageBoxViewModel.DefaultFlowDirection"/></param>
        /// <param name="textAlignment">The <see cref="System.Windows.TextAlignment"/> to use, overrides the <see cref="MessageBoxViewModel.DefaultTextAlignment"/></param>
        public void Setup(
            string messageBoxText,
            string caption                 = null,
            MessageBoxButton buttons       = MessageBoxButton.OK,
            MessageBoxImage icon           = MessageBoxImage.None,
            MessageBoxResult defaultResult = MessageBoxResult.None,
            MessageBoxResult cancelResult  = MessageBoxResult.None,
            IDictionary <MessageBoxResult, string> buttonLabels = null,
            FlowDirection?flowDirection = null,
            TextAlignment?textAlignment = null)
        {
            this.Text        = messageBoxText;
            this.DisplayName = caption;
            this.Icon        = icon;

            var buttonList = new BindableCollection <LabelledValue <MessageBoxResult> >();

            this.ButtonList = buttonList;
            foreach (var val in ButtonToResults[buttons])
            {
                string label;
                if (buttonLabels == null || !buttonLabels.TryGetValue(val, out label))
                {
                    label = ButtonLabels[val];
                }

                var lbv = new LabelledValue <MessageBoxResult>(label, val);
                buttonList.Add(lbv);
                if (val == defaultResult)
                {
                    this.DefaultButton = lbv;
                }
                else if (val == cancelResult)
                {
                    this.CancelButton = lbv;
                }
            }
            // If they didn't specify a button which we showed, then pick a default, if we can
            if (this.DefaultButton == null)
            {
                if (defaultResult == MessageBoxResult.None && this.ButtonList.Any())
                {
                    this.DefaultButton = buttonList[0];
                }
                else
                {
                    throw new ArgumentException("DefaultButton set to a button which doesn't appear in Buttons");
                }
            }
            if (this.CancelButton == null)
            {
                if (cancelResult == MessageBoxResult.None && this.ButtonList.Any())
                {
                    this.CancelButton = buttonList.Last();
                }
                else
                {
                    throw new ArgumentException("CancelButton set to a button which doesn't appear in Buttons");
                }
            }

            this.FlowDirection = flowDirection ?? DefaultFlowDirection;
            this.TextAlignment = textAlignment ?? DefaultTextAlignment;
        }