Beispiel #1
0
        public MessageResultEventArgs(MessageButton button)
        {
            this.Button = button;

            if (button.Result is MessageResult)
            {
                this.Result = (MessageResult)button.Result;
            }
            else
            {
                this.Result = MessageResult.Other;
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Gets the default OK <see cref="MessageButton" />.
        /// </summary>
        /// <returns>MessageButton.</returns>
        private MessageButton GetDefaultOKButton()
        {
            var button = new Button {
                Width = 80, Height = 22, Content = "OK", IsDefault = true
            };

            var messageButton = new MessageButton
            {
                Button           = button,
                RightToLeftIndex = 0,
                Result           = MessageResult.OK
            };

            return(messageButton);
        }
Beispiel #3
0
        /// <summary>
        ///     Gets the default Cancel <see cref="MessageButton" />.
        /// </summary>
        /// <returns>MessageButton.</returns>
        private MessageButton GetDefaultCancelButton()
        {
            var button = new Button {
                Width = 80, Height = 22, Content = "Cancel", IsCancel = true
            };

            var messageButton = new MessageButton {
                Button = button
            };

            messageButton.RightToLeftIndex = 1;
            messageButton.Result           = MessageResult.Cancel;

            return(messageButton);
        }
Beispiel #4
0
        /// <summary>
        ///     Invokes the commands.
        /// </summary>
        /// <param name="buttonClicked">The <see cref="MessageButton" /> containing the button that was clicked.</param>
        /// <param name="resultOfButtonClick">The <see cref="MessageResult" /> associated with the button clicked.</param>
        private void InvokeCommands(MessageButton buttonClicked, MessageResult resultOfButtonClick)
        {
            var buttonResult = (buttonClicked != null) ? buttonClicked.Result ?? resultOfButtonClick : resultOfButtonClick;

            switch (resultOfButtonClick)
            {
            case MessageResult.OK:
                this.ResultOKCommand.ExecuteIfAbleTo(buttonResult);
                break;

            case MessageResult.Cancel:
                this.ResultCancelCommand.ExecuteIfAbleTo(buttonResult);
                break;

            case MessageResult.Other:
                this.ResultOtherCommand.ExecuteIfAbleTo(buttonResult);
                break;
            }

            this.ResultCommand.ExecuteIfAbleTo(buttonResult);
            this.result = resultOfButtonClick;
        }
Beispiel #5
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var valueType = value.GetType();

            if (valueType == typeof(Button))
            {
                var button = (Button)value;
                return(new MessageButton {
                    Button = button
                });
            }
            if (valueType == typeof(string))
            {
                var textFragments = value.ToString().Split(';');
                var button        = new Button {
                    Content = textFragments[0]
                };
                var mbutton = new MessageButton {
                    Button = button
                };

                button.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                button.Width  = Math.Max(80, button.DesiredSize.Width);
                button.Height = Math.Max(22, button.DesiredSize.Height);

                if (textFragments.Length > 1)
                {
                    var rightToLeftIndex = 0;
                    if (int.TryParse(textFragments[1], out rightToLeftIndex))
                    {
                        mbutton.RightToLeftIndex = rightToLeftIndex;
                    }
                }

                if (textFragments.Length > 2)
                {
                    var resultFragment = textFragments[2].ToUpper();
                    if (string.Equals(resultFragment, "OK"))
                    {
                        mbutton.Result = MessageResult.OK;
                    }
                    else if (string.Equals(resultFragment, "CANCEL"))
                    {
                        mbutton.Result = MessageResult.Cancel;
                    }
                    else if (string.Equals(resultFragment, "OTHER"))
                    {
                        mbutton.Result = MessageResult.Other;
                    }
                    else if (string.Equals(resultFragment, "NULL"))
                    {
                        mbutton.Result = null;
                    }
                    else if (!string.Equals(resultFragment, string.Empty))
                    {
                        mbutton.Result = textFragments[2];
                    }
                }

                return(mbutton);
            }

            return(base.ConvertFrom(context, culture, value));
        }