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

OnApplyTemplate() public method

public OnApplyTemplate ( ) : void
return void
		public override void OnApplyTemplate ()
		{
			base.OnApplyTemplate ();

			UpdateVisualState (false);

			IsDropDownOpen = false;
			
			_contentPresenter = GetTemplateChild ("ContentPresenter") as ContentPresenter;
			_popup = GetTemplateChild ("Popup") as Popup;
			_dropDownToggle = GetTemplateChild ("DropDownToggle") as ToggleButton;

			if (_contentPresenter != null) {
				NothingSelectedFallback = _contentPresenter.Content;
			}

			if (_popup != null) {
				UpdatePopupMaxHeight (MaxDropDownHeight);
				_popup.CatchClickedOutside ();
				_popup.ClickedOutside += delegate { 
					IsDropDownOpen = false; 
				};

				// The popup will never receive a key press event so we need to chain the event
				// using Popup.Child
				if (_popup.Child != null) {
					_popup.Child.KeyDown += delegate(object sender, KeyEventArgs e) {
						OnKeyDown (e);
					};
					((FrameworkElement) _popup.RealChild).SizeChanged += UpdatePopupSizeAndPosition;
				}
			}
			if (_dropDownToggle != null) {
				_dropDownToggle.Checked += delegate {
						IsDropDownOpen = true;
				};
				_dropDownToggle.Unchecked += delegate {
						IsDropDownOpen = false;
				};
			}
			
			UpdateVisualState (false);
			UpdateDisplayedItem (SelectedItem);
		}