/// <summary> /// Updates the expanded visual state. /// </summary> public void UpdateExpandedState() { if (this.IsExpanded) { this.SelectedItem = this.ConfirmedSelectedItem; if (this.ConfirmedSelectedItem != null) { this.ScrollIntoView(this.ConfirmedSelectedItem); } this.GoToVisualState("Expanded", true); if (this.selectedItemButton != null) { VisualStateManager.GoToState(this.selectedItemButton, "Normal", false); } } else { this.focusSelectedItem = true; this.GoToVisualState("Collapsed", true); if (this.Collapsed != null) { this.Collapsed(this, EventArgs.Empty); } if (this.IsFocused && this.selectedItemButton != null) { FocusHelper.FocusControl(this.selectedItemButton); } } }
/// <summary> /// Adds event handlers to today and close buttons. /// </summary> /// <param name="sender">The calendar.</param> /// <param name="e">Routed Event Args.</param> private void DateInputBox_CalendarOpened(object sender, RoutedEventArgs e) { #if SILVERLIGHT this.Calendar = ((this.GetTemplateChild("Popup") as System.Windows.Controls.Primitives.Popup).Child as Panel).Children[1] as System.Windows.Controls.Calendar; #else this.Calendar = (this.GetTemplateChild("PART_Popup") as System.Windows.Controls.Primitives.Popup).Child as Microsoft.Windows.Controls.Calendar; if (this.Calendar != null) { this.Calendar.SelectedDate = this.SelectedDate; FocusHelper.FocusControl(this.Calendar); } if (DateInputBox.TodayButtonsByCalendar.ContainsKey(this.Calendar)) { this.UpdateTodayButton(DateInputBox.TodayButtonsByCalendar[this.Calendar]); DateInputBox.TodayButtonsByCalendar.Remove(this.Calendar); } if (DateInputBox.CloseButtonsByCalendar.ContainsKey(this.Calendar)) { this.UpdateCloseButton(DateInputBox.CloseButtonsByCalendar[this.Calendar]); DateInputBox.CloseButtonsByCalendar.Remove(this.Calendar); } #endif if (this.Calendar != null) { FocusHelper.FocusControl(this.Calendar); } }
/// <summary> /// Sets the is focused flag to true. /// </summary> /// <param name="sender">The optional field container.</param> /// <param name="e">Routed Event Args.</param> private void OptionalFieldContainer_GotFocus(object sender, RoutedEventArgs e) { CompositionTarget.Rendering -= new EventHandler(this.CompositionTargetRendering_LostFocus); this.isFocused = true; if (this.showFieldButton.Visibility == Visibility.Visible && this.showFieldButton != null && e.OriginalSource != this.showFieldButton) { FocusHelper.FocusControl(this.showFieldButton); } }
/// <summary> /// Gives focus to the first control in the tree. /// </summary> /// <param name="sender">The label area element.</param> /// <param name="e">Mouse Button Event Args.</param> private void LabelAreaElement_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { UIElement content = this.Content as UIElement; if (content != null) { Control control = LabeledContentControl.GetFirstControl(content); if (control != null) { FocusHelper.FocusControl(control); } } }
/// <summary> /// Collapses the list, if behaviour is not overriden. /// </summary> /// <param name="sender">The cascading list box item.</param> /// <param name="e">Selected Event Args.</param> private void CascadingListBoxItem_Selected(object sender, SelectedEventArgs e) { if (this.CollapseOnSelection && !e.Handled) { this.IsExpanded = false; } FocusHelper.FocusControl(this); if (e.SelectedItem != this.OtherItem) { this.RaiseItemSelected(); } }
/// <summary> /// Moves focus to the correct control. /// </summary> /// <param name="sender">The cascading list box.</param> /// <param name="e">Routed Event Args.</param> private void CascadingListBox_GotFocus(object sender, RoutedEventArgs e) { CompositionTarget.Rendering -= new EventHandler(this.CompositionTargetRendering_LostFocus); this.isFocused = true; #if !SILVERLIGHT if (e.OriginalSource == this || e.OriginalSource == this.selectedItemButton || e.OriginalSource is CascadingListBoxItem) { this.IsTabStop = false; } #endif #if !SILVERLIGHT if (this.lastFocusedElement != e.OriginalSource && this.SelectedItem == null || (!this.IsExpanded && e.OriginalSource is CascadingListBoxItem)) { this.lastFocusedElement = e.OriginalSource; } if (!this.IsExpanded && (e.OriginalSource is CascadingListBoxItem) && this.lastFocusedElement == e.OriginalSource && this.selectedItemButton != null) { FocusHelper.FocusControl(this.selectedItemButton); } else { this.lastFocusedElement = e.OriginalSource; } #endif if (this.focusSelectedItem && this.IsExpanded && this.ConfirmedSelectedItem != null && this.containersByItem.ContainsKey(this.ConfirmedSelectedItem)) { this.containersByItem[this.ConfirmedSelectedItem].Focus(); this.focusSelectedItem = false; } else if (this.IsExpanded && this.SelectedItem != null && this.containersByItem.ContainsKey(this.SelectedItem)) { this.containersByItem[this.SelectedItem].Focus(); } else if (this.IsExpanded && (this.SelectedItem == null || this.SelectedItem == this.OtherItem) && this.Items.Count > 0 && (!this.Items.Contains(this.OtherItem) || this.SelectedIndex != this.Items.IndexOf(this.OtherItem))) { this.SelectedItem = this.Items[0]; if (this.containersByItem.ContainsKey(this.Items[0])) { this.containersByItem[this.Items[0]].Focus(); } } else if (!this.IsExpanded && this.selectedItemButton != null && this.ConfirmedSelectedItem != null && e.OriginalSource != this.selectedItemButton) { this.selectedItemButton.Focus(); } }
/// <summary> /// Updates the UI. /// </summary> /// <param name="isFieldShowing">Whether the field is showing.</param> private void UpdateIsFieldShowing(bool isFieldShowing) { if (this.contentPresenter != null && this.showFieldButton != null) { if (isFieldShowing && this.Content != null) { this.contentPresenter.Visibility = Visibility.Visible; this.showFieldButton.Visibility = Visibility.Collapsed; if (this.isFocused) { Control control = this.Control != null ? this.Control : GetFirstControl(this.Content as UIElement); SplitComboBox splitComboBox = control as SplitComboBox; if (splitComboBox != null) { splitComboBox.OpenDropDownOnGotFocus = true; } FocusHelper.FocusControl(control); } if (this.Expanded != null) { this.Expanded(this, EventArgs.Empty); } } else { this.showFieldButton.Visibility = Visibility.Visible; this.contentPresenter.Visibility = Visibility.Collapsed; if (this.isFocused) { FocusHelper.FocusControl(this.showFieldButton); } if (this.Collapsed != null) { this.Collapsed(this, EventArgs.Empty); } } } }
/// <summary> /// Sets the text box text, and selects all. /// </summary> /// <param name="sender">The composition target.</param> /// <param name="e">Event Args.</param> private void CompositionTargetRendering_SetTextBoxText(object sender, EventArgs e) { CompositionTarget.Rendering -= new EventHandler(this.CompositionTargetRendering_SetTextBoxText); this.textBox.Text = this.SelectedDateText; FocusHelper.FocusControl(this.textBox); }