Exemplo n.º 1
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;
        }
Exemplo n.º 2
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));
            }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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();
        }