コード例 #1
0
        private void TimeListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                TimeItem selectedTimeListItem = ( TimeItem )e.AddedItems[0];
                var      time = selectedTimeListItem.Time;

                if (this.UpdateValueOnEnterKey)
                {
                    var currentValue = this.ConvertTextToValue(this.TextBox.Text);
                    var date         = currentValue ?? this.ContextNow;
                    var newValue     = new DateTime(date.Year, date.Month, date.Day, time.Hours, time.Minutes, time.Seconds, time.Milliseconds, date.Kind);
                    this.TextBox.Text = newValue.ToString(this.GetFormatString(this.Format), this.CultureInfo);
                }
                else
                {
                    var date = this.Value ?? this.ContextNow;
                    this.Value = new DateTime(date.Year, date.Month, date.Day, time.Hours, time.Minutes, time.Seconds, time.Milliseconds, date.Kind);
                }
            }
        }
コード例 #2
0
ファイル: TimePicker.cs プロジェクト: CreateIdea/BI_Wizard
        protected override void Popup_Opened(object sender, EventArgs e)
        {
            base.Popup_Opened(sender, e);

            if (_timeListBox != null)
            {
                this.UpdateListBoxItems();

                TimeSpan time        = (Value != null) ? Value.Value.TimeOfDay : StartTimeDefaultValue;
                TimeItem nearestItem = this.GetNearestTimeItem(time);
                if (nearestItem != null)
                {
                    _timeListBox.ScrollIntoView(nearestItem);
                    ListBoxItem listBoxItem = ( ListBoxItem )_timeListBox.ItemContainerGenerator.ContainerFromItem(nearestItem);
                    if (listBoxItem != null)
                    {
                        listBoxItem.Focus();
                    }
                }
            }
        }