Ejemplo n.º 1
0
            /// <summary>
            /// Defines the formatting type <see cref="FormattingAfter"/>.
            /// </summary>
            /// <param name="state"> </param>
            /// <returns>The value of the  <see cref="FormattingAfter"/></returns>
            private void SetFormattingType(ProcessingState state)
            {
                FormattingAfter formattingAfter;

                if (_textBeforeChangingNotNull.IsNullOrEmpty() &&
                    state.UnformattedValue.IsNullOrEmpty())
                {
                    formattingAfter = FormattingAfter.EmptyValueBeforeAndNow;
                }
                else if (_textBeforeChangingNotNull.IsNotNullOrEmpty() &&
                         state.UnformattedValue.IsNullOrEmpty())
                {
                    formattingAfter = FormattingAfter.EmptyValueBecome;
                }
                else if (state.UnformattedValue == _textBeforeChangingNotNull)
                {
                    formattingAfter = FormattingAfter.ResettingTheSame;
                }
                else if (Math.Abs(state.UnformattedValue.Length - _textBeforeChangingNotNull.Length) != 1)
                {
                    formattingAfter = FormattingAfter.GroupPastingOrDeletion;
                }
                else
                {
                    var subtraction = state.UnformattedValue.Length - _textBeforeChangingNotNull.Length;
                    formattingAfter = 0 < subtraction
                                                ? FormattingAfter.OneSymbolAdded
                                                : FormattingAfter.OneSymbolDeleted;
                }

                state.FormattingType = formattingAfter;

                NumberToMoneyConverter.WriteLogAction(() => String.Format("  !! FormattingType = {0}", formattingAfter));
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Formats the text and manages the caret's position.<para/>
        /// Starts a recursion if it invoked from the TextChangent event handler.
        /// </summary>
        private void FormatTextAndManageCaretInRecursion(out Boolean textFormatted)
        {
            var textBox = this;

            var selectionStart   = textBox.SelectionStart;
            var unformattedValue = textBox.Text ?? String.Empty;

            if (IsRecursion())
            {
                textFormatted = true;

                textBox.Text           = String.Empty;
                textBox.SelectionStart = 0;

                return;
            }

            String formattedText;

            Converter.Process(unformattedValue, out formattedText, ref selectionStart);

            textFormatted = unformattedValue != formattedText;
            if (textFormatted)
            {
                NumberToMoneyConverter.WriteLogAction(() => String.Format(" = Text = {0}", formattedText));
                // It starts the recursion.
                textBox.Text = formattedText;
            }

            NumberToMoneyConverter.WriteLogAction(() => String.Format(" = SelectionStart = {0}", selectionStart));
            textBox.SelectionStart = selectionStart;
        }
Ejemplo n.º 3
0
        public void InitiatingSettings()
        {
            var converter = new NumberToMoneyConverter
            {
                DecimalSeparator = Char.MinValue,
            };

            Assert.IsTrue(converter.DecimalSeparator == NumberToMoneyConverter.DefaultDecimalSeparator);
        }
Ejemplo n.º 4
0
        public void InitiatingSettings()
        {
            var separator = Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator.ToCharFirst();
            var converter = new NumberToMoneyConverter
            {
                DecimalSeparator            = separator,
                DecimalSeparatorAlternative = separator,
            };

            // It's allowable but not important behaviour.
            Assert.IsTrue(converter.DecimalSeparatorAlternative == converter.DecimalSeparator);
        }
Ejemplo n.º 5
0
        private void textBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            var textBox = this;

            NumberToMoneyConverter.WriteLogAction(() => String.Format("* TextChanged. SelectionStart = {0}. SelectionLength = {1}. Text = {2}",
                                                                      textBox.SelectionStart,
                                                                      textBox.SelectionLength,
                                                                      textBox.Text)
                                                  );

            ProcessText();
        }
Ejemplo n.º 6
0
        void textBox_LostFocus(object sender, RoutedEventArgs e)
        {
            var textBox = this;

            NumberToMoneyConverter.WriteLogAction(() => String.Format("* LostFocus. SelectionStart = {0}. SelectionLength = {1}. Text = {2}",
                                                                      textBox.SelectionStart,
                                                                      textBox.SelectionLength,
                                                                      textBox.Text)
                                                  );

            SetFocusState(FocusState.No);
            ProcessText();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Checks and sets a data binding for the <see cref="TextBox.TextProperty"/>.
        /// </summary>
        /// <param name="converter">The converter with a custom formatting logic.</param>
        private void CorrectBinding(NumberToMoneyConverter converter)
        {
            GetBindingExpression(TextProperty)
            .InvokeNotNull(el =>
            {
                var binding = new Binding(el.ParentBinding)
                {
                    // it3xl.com: Update Source Trigger is our job.
                    UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
                    Mode = BindingMode.TwoWay,

                    // it3xl.com: Only our converter is appropriate. It's the main logic out here.
                    Converter = converter,
                };

                SetBinding(TextProperty, binding);
            });
        }
Ejemplo n.º 8
0
        public MoneyTextBox()
        {
            Converter = new NumberToMoneyConverter();

            Loaded += LoadedHandler;
        }