Inheritance: System.Windows.FrameworkElement
 private string GetDisplayText(object dataItem)
 {
     if (BindingEvaluator == null) {
         BindingEvaluator = new BindingEvaluator(new Binding(DisplayMember));
     }
     if (dataItem == null) {
         return string.Empty;
     }
     if (string.IsNullOrEmpty(DisplayMember)) {
         return dataItem.ToString();
     }
     return BindingEvaluator.Evaluate(dataItem);
 }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            Editor = Template.FindName(PartEditor, this) as TextBox;
            Popup = Template.FindName(PartPopup, this) as Popup;
            ItemsSelector = Template.FindName(PartSelector, this) as Selector;
            BindingEvaluator = new BindingEvaluator(new Binding(DisplayMember));

            if (Editor != null) {
                Editor.TextChanged += OnEditorTextChanged;
                Editor.PreviewKeyDown += OnEditorKeyDown;
                Editor.LostFocus += OnEditorLostFocus;

                if (SelectedItem != null) {
                    Editor.Text = BindingEvaluator.Evaluate(SelectedItem);
                }
            }

            if (Popup != null) {
                Popup.StaysOpen = false;
                Popup.Opened += OnPopupOpened;
                Popup.Closed += OnPopupClosed;
            }
            if (ItemsSelector != null) {
                SelectionAdapter = new SelectionAdapter(ItemsSelector);
                SelectionAdapter.Commit += OnSelectionAdapterCommit;
                SelectionAdapter.Cancel += OnSelectionAdapterCancel;
                SelectionAdapter.SelectionChanged += OnSelectionAdapterSelectionChanged;
            }
        }