public override void OnApplyTemplate()
{
#if !SILVERLIGHT
if(TextBox != null)
{
TextBox.PreviewKeyDown -= OnTextBoxPreviewKeyDown;
}
#endif
if(DropDownPopup != null)
{
DropDownPopup.Closed -= DropDownPopupClosed;
DropDownPopup.FocusChanged -= OnDropDownFocusChanged;
DropDownPopup.UpdateVisualStates -= OnDropDownPopupUpdateVisualStates;
DropDownPopup.BeforeOnApplyTemplate();
DropDownPopup = null;
}
base.OnApplyTemplate();
// Set the template parts. Individual part setters remove and add
// any event handlers.
Popup popup = GetTemplateChild(ElementPopup) as Popup;
if(popup != null)
{
DropDownPopup = new PopupHelper(this, popup) { MaxDropDownHeight = MaxDropDownHeight };
DropDownPopup.AfterOnApplyTemplate();
DropDownPopup.Closed += DropDownPopupClosed;
DropDownPopup.FocusChanged += OnDropDownFocusChanged;
DropDownPopup.UpdateVisualStates += OnDropDownPopupUpdateVisualStates;
}
SelectionAdapter = GetSelectionAdapterPart();
TextBox = GetTemplateChild(ElementTextBox) as TextBox;
#if !SILVERLIGHT
if(TextBox != null)
{
TextBox.PreviewKeyDown += OnTextBoxPreviewKeyDown;
}
#endif
Interaction.OnApplyTemplateBase();
// If the drop down property indicates that the popup is open,
// flip its value to invoke the changed handler.
if(IsDropDownOpen && DropDownPopup != null && !DropDownPopup.IsOpen)
{
OpeningDropDown(false);
}
}