示例#1
0
        private void SetSelectedDate()
        {
            if (_textBox != null)
            {
                if (!string.IsNullOrEmpty(_textBox.Text))
                {
                    var s = _textBox.Text;

                    if (SelectedDate != null)
                    {
                        // If the string value of the SelectedDate and the TextBox string value are equal,
                        // we do not parse the string again
                        // if we do an extra parse, we lose data in M/d/yy format
                        // ex: SelectedDate = DateTime(1008,12,19) but when "12/19/08" is parsed it is interpreted as DateTime(2008,12,19)
                        var selectedDate = DateTimeToString(SelectedDate.Value);

                        if (string.Compare(selectedDate, s, StringComparison.Ordinal) == 0)
                        {
                            return;
                        }
                    }

                    var d = SetTextBoxValue(s);
                    if (!SelectedDate.Equals(d))
                    {
                        this.SetCurrentValueInternal(SelectedDateProperty, d);
                        this.SetCurrentValueInternal(DisplayDateProperty, d);
                    }
                }
                else
                {
                    if (SelectedDate.HasValue)
                    {
                        this.SetCurrentValueInternal(SelectedDateProperty, (DateTime?)null);
                    }
                }
            }
            else
            {
                var d = SetTextBoxValue(_defaultText);
                if (!SelectedDate.Equals(d))
                {
                    this.SetCurrentValueInternal(SelectedDateProperty, d);
                }
            }
        }
示例#2
0
        private void SetSelectedDate()
        {
            if (_textBox != null)
            {
                if (!string.IsNullOrEmpty(_textBox.Text))
                {
                    string s = _textBox.Text;

                    if (SelectedDate != null)
                    {
                        // If the string value of the SelectedDate and the
                        // TextBox string value are equal, we do not parse the
                        // string again if we do an extra parse, we lose data in
                        // M/d/yy format.
                        // ex: SelectedDate = DateTime(1008,12,19) but when
                        // "12/19/08" is parsed it is interpreted as
                        // DateTime(2008,12,19)
                        string selectedDate = DateTimeToString(SelectedDate.Value);
                        if (selectedDate == s)
                        {
                            return;
                        }
                    }
                    DateTime?d = SetTextBoxValue(s);
                    if (!SelectedDate.Equals(d))
                    {
                        SelectedDate = d;
                    }
                }
                else
                {
                    if (SelectedDate != null)
                    {
                        SelectedDate = null;
                    }
                }
            }
            else
            {
                DateTime?d = SetTextBoxValue(_defaultText);
                if (!SelectedDate.Equals(d))
                {
                    SelectedDate = d;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Updates selected date according to current Text property value
        /// </summary>
        private void SetSelectedDate()
        {
            var text = GetValue(TextProperty)?.ToString();

            if (text != null)
            {
                if (!string.IsNullOrEmpty(text))
                {
                    if (SelectedDate.HasValue &&
                        SetTextFromDate(SelectedDate.Value.ToString()) == text)
                    {
                        return;
                    }

                    var dt = ParseText(text);
                    if (SelectedDate.Equals(dt))
                    {
                        return;
                    }

                    SetCurrentValue(SelectedDateProperty, dt);
                }
                else
                {
                    if (!SelectedDate.HasValue)
                    {
                        return;
                    }

                    //Behavior of Silverlight component
                    SetCurrentValue(SelectedDateProperty, new DateTime());
                }
            }
            else
            {
                var dt = ParseText(_defaultText);
                if (SelectedDate.Equals(dt))
                {
                    return;
                }

                SetCurrentValue(SelectedDateProperty, dt);
            }
        }