示例#1
0
        private void ApplyFormat()
        {
            _formatInfo = DateTimeFormatHelper.GetDateTimeFormatInfo(Format, true);

            IsYearShortFormat = _formatInfo.IsYearShortFormat;
            NumericTBYear.SetCurrentValue(NumericTextBox.MinValueProperty, (double)(_formatInfo.IsYearShortFormat ? 0 : 1));
            NumericTBYear.SetCurrentValue(NumericTextBox.MaxValueProperty, (double)(_formatInfo.IsYearShortFormat ? 99 : 3000));

            EnableOrDisableYearConverterDependingOnFormat();

            NumericTBDay.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.DayFormat.Length));
            NumericTBMonth.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.MonthFormat.Length));
            NumericTBYear.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.YearFormat.Length));

            UnsubscribeNumericTextBoxes();

            Grid.SetColumn(NumericTBDay, GetPosition(_formatInfo.DayPosition));
            Grid.SetColumn(NumericTBMonth, GetPosition(_formatInfo.MonthPosition));
            Grid.SetColumn(NumericTBYear, GetPosition(_formatInfo.YearPosition));

            Grid.SetColumn(ToggleButtonD, GetPosition(_formatInfo.DayPosition) + 1);
            Grid.SetColumn(ToggleButtonMo, GetPosition(_formatInfo.MonthPosition) + 1);
            Grid.SetColumn(ToggleButtonY, GetPosition(_formatInfo.YearPosition) + 1);

            _textBoxes[_formatInfo.DayPosition]   = NumericTBDay;
            _textBoxes[_formatInfo.MonthPosition] = NumericTBMonth;
            _textBoxes[_formatInfo.YearPosition]  = NumericTBYear;

            // Fix tab order inside control.
            NumericTBDay.SetCurrentValue(TabIndexProperty, _formatInfo.DayPosition);
            NumericTBMonth.SetCurrentValue(TabIndexProperty, _formatInfo.MonthPosition);
            NumericTBYear.SetCurrentValue(TabIndexProperty, _formatInfo.YearPosition);
            DatePickerIcon.SetCurrentValue(TabIndexProperty, Int32.MaxValue);

            SubscribeNumericTextBoxes();

            Separator1.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator1);
            Separator2.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator2);
            Separator3.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator3);
        }
示例#2
0
 private void OnValueChanged(object oldValue, object newValue)
 {
     Separator1.SetCurrentValue(TextBlock.TextProperty, newValue == null ? string.Empty : ".");
     Separator2.SetCurrentValue(TextBlock.TextProperty, newValue == null ? string.Empty : ":");
     Separator3.SetCurrentValue(TextBlock.TextProperty, newValue == null ? string.Empty : ":");
 }
示例#3
0
        private void ApplyFormat()
        {
            _formatInfo = DateTimeFormatHelper.GetDateTimeFormatInfo(Format, false);

            IsYearShortFormat = _formatInfo.IsYearShortFormat;
            NumericTBYear.SetCurrentValue(NumericTextBox.MinValueProperty, (double)(_formatInfo.IsYearShortFormat ? 0 : 1));
            NumericTBYear.SetCurrentValue(NumericTextBox.MaxValueProperty, (double)(_formatInfo.IsYearShortFormat ? 99 : 3000));

            IsHour12Format = _formatInfo.IsHour12Format.Value;
            NumericTBHour.SetCurrentValue(NumericTextBox.MinValueProperty, (double)(_formatInfo.IsHour12Format.Value ? 1 : 0));
            NumericTBHour.SetCurrentValue(NumericTextBox.MaxValueProperty, (double)(_formatInfo.IsHour12Format.Value ? 12 : 23));
            ToggleButtonH.SetCurrentValue(TagProperty, _formatInfo.IsHour12Format.Value ? DateTimePart.Hour12 : DateTimePart.Hour);

            IsAmPmShortFormat = _formatInfo.IsAmPmShortFormat.Value;

            EnableOrDisableYearConverterDependingOnFormat();
            EnableOrDisableHourConverterDependingOnFormat();
            EnableOrDisableAmPmConverterDependingOnFormat();

            ListTBAmPm.SetCurrentValue(ListTextBox.ListOfValuesProperty, new List <string>()
            {
                Meridiems.GetAmForFormat(_formatInfo),
                Meridiems.GetPmForFormat(_formatInfo)
            });

            NumericTBDay.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.DayFormat.Length));
            NumericTBMonth.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.MonthFormat.Length));
            NumericTBYear.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.YearFormat.Length));
            NumericTBHour.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.HourFormat.Length));
            NumericTBMinute.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.MinuteFormat.Length));
            NumericTBSecond.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.SecondFormat.Length));

            UnsubscribeNumericTextBoxes();

            Grid.SetColumn(NumericTBDay, GetPosition(_formatInfo.DayPosition));
            Grid.SetColumn(NumericTBMonth, GetPosition(_formatInfo.MonthPosition));
            Grid.SetColumn(NumericTBYear, GetPosition(_formatInfo.YearPosition));
            Grid.SetColumn(NumericTBHour, GetPosition(_formatInfo.HourPosition.Value));
            Grid.SetColumn(NumericTBMinute, GetPosition(_formatInfo.MinutePosition.Value));
            Grid.SetColumn(NumericTBSecond, GetPosition(_formatInfo.SecondPosition.Value));
            Grid.SetColumn(ListTBAmPm, GetPosition(_formatInfo.AmPmPosition.HasValue == false ? 6 : _formatInfo.AmPmPosition.Value));

            Grid.SetColumn(ToggleButtonD, GetPosition(_formatInfo.DayPosition) + 1);
            Grid.SetColumn(ToggleButtonMo, GetPosition(_formatInfo.MonthPosition) + 1);
            Grid.SetColumn(ToggleButtonY, GetPosition(_formatInfo.YearPosition) + 1);
            Grid.SetColumn(ToggleButtonH, GetPosition(_formatInfo.HourPosition.Value) + 1);
            Grid.SetColumn(ToggleButtonM, GetPosition(_formatInfo.MinutePosition.Value) + 1);
            Grid.SetColumn(ToggleButtonS, GetPosition(_formatInfo.SecondPosition.Value) + 1);
            Grid.SetColumn(ToggleButtonT, GetPosition(_formatInfo.AmPmPosition.HasValue == false ? 6 : _formatInfo.AmPmPosition.Value) + 1);

            // Fix positions which could be broken, because of AM/PM textblock.
            int dayPos = _formatInfo.DayPosition, monthPos = _formatInfo.MonthPosition, yearPos = _formatInfo.YearPosition,
                hourPos = _formatInfo.HourPosition.Value, minutePos = _formatInfo.MinutePosition.Value, secondPos = _formatInfo.SecondPosition.Value,
                amPmPos = _formatInfo.AmPmPosition.HasValue == false ? 6 : _formatInfo.AmPmPosition.Value;

            FixNumericTextBoxesPositions(ref dayPos, ref monthPos, ref yearPos, ref hourPos, ref minutePos, ref secondPos, ref amPmPos);

            _textBoxes[dayPos]    = NumericTBDay;
            _textBoxes[monthPos]  = NumericTBMonth;
            _textBoxes[yearPos]   = NumericTBYear;
            _textBoxes[hourPos]   = NumericTBHour;
            _textBoxes[minutePos] = NumericTBMinute;
            _textBoxes[secondPos] = NumericTBSecond;
            _textBoxes[amPmPos]   = ListTBAmPm;

            // Fix tab order inside control.
            NumericTBDay.SetCurrentValue(TabIndexProperty, dayPos);
            NumericTBMonth.SetCurrentValue(TabIndexProperty, monthPos);
            NumericTBYear.SetCurrentValue(TabIndexProperty, yearPos);
            NumericTBHour.SetCurrentValue(TabIndexProperty, hourPos);
            NumericTBMinute.SetCurrentValue(TabIndexProperty, minutePos);
            NumericTBSecond.SetCurrentValue(TabIndexProperty, secondPos);
            ListTBAmPm.SetCurrentValue(TabIndexProperty, amPmPos);
            DatePickerIcon.SetCurrentValue(TabIndexProperty, Int32.MaxValue);

            SubscribeNumericTextBoxes();

            Separator1.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator1);
            Separator2.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator2);
            Separator3.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator3);
            Separator4.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator4);
            Separator5.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator5);
            Separator6.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator6);
            Separator7.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator7);
        }
示例#4
0
        private void ApplyFormat()
        {
            _applyingFormat = true;

            try
            {
                var format = Format;
                _formatInfo = DateTimeFormatHelper.GetDateTimeFormatInfo(format);
                var hasLongTimeFormat = !(_formatInfo.HourFormat is null ||
                                          _formatInfo.MinuteFormat is null ||
                                          _formatInfo.SecondFormat is null);

                var hasAnyTimeFormat = !(_formatInfo.HourFormat is null &&
                                         _formatInfo.MinuteFormat is null &&
                                         _formatInfo.SecondFormat is null);

                SetCurrentValue(HideTimeProperty, !hasAnyTimeFormat || _hideTime);

                if (!hasLongTimeFormat)
                {
                    var timePattern = DateTimeFormatHelper.ExtractTimePatternFromFormat(format);
                    if (!string.IsNullOrEmpty(timePattern))
                    {
                        timePattern = DateTimeFormatHelper.FindMatchedLongTimePattern(CultureInfo.CurrentUICulture, timePattern);
                    }

                    if (string.IsNullOrEmpty(timePattern))
                    {
                        timePattern = CultureInfo.CurrentUICulture.DateTimeFormat.LongTimePattern;
                    }

                    var datePattern = DateTimeFormatHelper.ExtractDatePatternFromFormat(format);

                    format = $"{datePattern} {timePattern}";

                    _formatInfo = DateTimeFormatHelper.GetDateTimeFormatInfo(format);
                }

                if (!hasAnyTimeFormat)
                {
                }

                IsYearShortFormat = _formatInfo.IsYearShortFormat;
                NumericTBYear.SetCurrentValue(NumericTextBox.MinValueProperty, (double)(_formatInfo.IsYearShortFormat ? 0 : 1));
                NumericTBYear.SetCurrentValue(NumericTextBox.MaxValueProperty, (double)(_formatInfo.IsYearShortFormat ? 99 : 3000));

                var isHour12Format = _formatInfo.IsHour12Format ?? true;
                IsHour12Format = isHour12Format;
                NumericTBHour.SetCurrentValue(NumericTextBox.MinValueProperty, (double)(isHour12Format ? 1 : 0));
                NumericTBHour.SetCurrentValue(NumericTextBox.MaxValueProperty, (double)(isHour12Format ? 12 : 23));
                ToggleButtonH.SetCurrentValue(TagProperty, isHour12Format ? DateTimePart.Hour12 : DateTimePart.Hour);

                IsAmPmShortFormat = _formatInfo.IsAmPmShortFormat.Value;

                EnableOrDisableYearConverterDependingOnFormat();
                EnableOrDisableHourConverterDependingOnFormat();
                EnableOrDisableAmPmConverterDependingOnFormat();

                ListTBAmPm.SetCurrentValue(ListTextBox.ListOfValuesProperty, new List <string>()
                {
                    Meridiems.GetAmForFormat(_formatInfo),
                    Meridiems.GetPmForFormat(_formatInfo)
                });

                NumericTBDay.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.DayFormat.Length));
                NumericTBMonth.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.MonthFormat.Length));
                NumericTBYear.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.YearFormat.Length));
                NumericTBHour.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.HourFormat.Length));
                NumericTBMinute.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.MinuteFormat.Length));
                NumericTBSecond.SetCurrentValue(NumericTextBox.FormatProperty, NumberFormatHelper.GetFormat(_formatInfo.SecondFormat?.Length ?? 0));

                UnsubscribeNumericTextBoxes();

                Grid.SetColumn(NumericTBDay, GetPosition(_formatInfo.DayPosition));
                Grid.SetColumn(NumericTBMonth, GetPosition(_formatInfo.MonthPosition));
                Grid.SetColumn(NumericTBYear, GetPosition(_formatInfo.YearPosition));
                Grid.SetColumn(NumericTBHour, GetPosition(_formatInfo.HourPosition.Value));
                Grid.SetColumn(NumericTBMinute, GetPosition(_formatInfo.MinutePosition.Value));
                Grid.SetColumn(NumericTBSecond, GetPosition(_formatInfo.SecondPosition ?? _defaultSecondFormatPosition));
                Grid.SetColumn(ListTBAmPm, GetPosition(_formatInfo.AmPmPosition ?? _defaultAmPmFormatPosition));

                Grid.SetColumn(ToggleButtonD, GetPosition(_formatInfo.DayPosition) + 1);
                Grid.SetColumn(ToggleButtonMo, GetPosition(_formatInfo.MonthPosition) + 1);
                Grid.SetColumn(ToggleButtonY, GetPosition(_formatInfo.YearPosition) + 1);
                Grid.SetColumn(ToggleButtonH, GetPosition(_formatInfo.HourPosition.Value) + 1);
                Grid.SetColumn(ToggleButtonM, GetPosition(_formatInfo.MinutePosition.Value) + 1);
                Grid.SetColumn(ToggleButtonS, GetPosition(_formatInfo.SecondPosition ?? _defaultSecondFormatPosition) + 1);

                //hide parts according to Hide options and format
                bool isHiddenManual = HideSeconds || HideTime;

                NumericTBSecond.SetCurrentValue(NumericTextBox.VisibilityProperty, _formatInfo.SecondFormat is null || isHiddenManual ? Visibility.Collapsed : Visibility.Visible);
                ToggleButtonS.SetCurrentValue(NumericTextBox.VisibilityProperty, _formatInfo.SecondFormat is null || isHiddenManual ? Visibility.Collapsed : Visibility.Visible);

                Grid.SetColumn(ToggleButtonT, GetPosition((_formatInfo.AmPmPosition ?? _defaultAmPmFormatPosition) + 1));

                // Fix positions which could be broken, because of AM/PM textblock.
                // Fix for seconds in a same way
                int dayPos = _formatInfo.DayPosition, monthPos = _formatInfo.MonthPosition, yearPos = _formatInfo.YearPosition,
                    hourPos = _formatInfo.HourPosition.Value, minutePos = _formatInfo.MinutePosition.Value, secondPos = _formatInfo.SecondPosition ?? 5,
                    amPmPos = _formatInfo.AmPmPosition ?? 6;
                FixNumericTextBoxesPositions(ref dayPos, ref monthPos, ref yearPos, ref hourPos, ref minutePos, ref secondPos, ref amPmPos);

                _textBoxes[dayPos]    = NumericTBDay;
                _textBoxes[monthPos]  = NumericTBMonth;
                _textBoxes[yearPos]   = NumericTBYear;
                _textBoxes[hourPos]   = NumericTBHour;
                _textBoxes[minutePos] = NumericTBMinute;
                _textBoxes[secondPos] = NumericTBSecond;
                _textBoxes[amPmPos]   = ListTBAmPm;

                // Fix tab order inside control.
                NumericTBDay.SetCurrentValue(TabIndexProperty, dayPos);
                NumericTBMonth.SetCurrentValue(TabIndexProperty, monthPos);
                NumericTBYear.SetCurrentValue(TabIndexProperty, yearPos);
                NumericTBHour.SetCurrentValue(TabIndexProperty, hourPos);
                NumericTBMinute.SetCurrentValue(TabIndexProperty, minutePos);
                NumericTBSecond.SetCurrentValue(TabIndexProperty, secondPos);
                ListTBAmPm.SetCurrentValue(TabIndexProperty, amPmPos);
                DatePickerIcon.SetCurrentValue(TabIndexProperty, Int32.MaxValue);

                SubscribeNumericTextBoxes();

                Separator1.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator1);
                Separator2.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator2);
                Separator3.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator3);
                Separator4.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator4);
                Separator5.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator5);
                Separator6.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator6);
                Separator7.SetCurrentValue(TextBlock.TextProperty, Value == null ? string.Empty : _formatInfo.Separator7);
            }
            finally
            {
                _applyingFormat = false;
            }
        }