System.Windows.Controls.ComboBox.IsDropDownOpenChanged C# (CSharp) Method

IsDropDownOpenChanged() private method

private IsDropDownOpenChanged ( DependencyObject sender, DependencyPropertyChangedEventArgs e ) : void
sender DependencyObject
e DependencyPropertyChangedEventArgs
return void
		void IsDropDownOpenChanged (DependencyObject sender, DependencyPropertyChangedEventArgs e)
		{
			bool open = (bool) e.NewValue;
			if (_popup != null)
				_popup.IsOpen = open;
			if (_dropDownToggle != null)
				_dropDownToggle.IsChecked = open;
			
			if (open) {
				ComboBoxItem t = null;
				FocusedIndex = Items.Count > 0 ? Math.Max (SelectedIndex, 0) : -1;
				if (FocusedIndex > -1)
					t = ItemContainerGenerator.ContainerFromIndex (FocusedIndex) as ComboBoxItem;

				// If the ItemsPresenter hasn't attached yet 't' will be null.
				// When the itemsPresenter attaches, focus will be set when the
				// item is loaded
				if (t != null)
					t.Focus ();

				UpdatePopupSizeAndPosition (this, EventArgs.Empty);
				LayoutUpdated += UpdatePopupSizeAndPosition;
				OnDropDownOpened (EventArgs.Empty);

				// Raises UIA Event
				AutomationPeer peer = ((ComboBox) sender).AutomationPeer;
				if (peer != null)
					peer.RaisePropertyChangedEvent (ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
					                                ExpandCollapseState.Collapsed,
									ExpandCollapseState.Expanded);
			} else {
				Focus ();

				LayoutUpdated -= UpdatePopupSizeAndPosition;

				OnDropDownClosed (EventArgs.Empty);

				// Raises UIA Event
				AutomationPeer peer = ((ComboBox) sender).AutomationPeer;
				if (peer != null)
					peer.RaisePropertyChangedEvent (ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
					                                ExpandCollapseState.Expanded,
									ExpandCollapseState.Collapsed);
			}

			UpdateDisplayedItem (open && SelectedItem is UIElement ? null : SelectedItem);
			UpdateVisualState (true);
		}