Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
 private void OnEditorKeyDown(object sender, KeyEventArgs e)
 {
     if (SelectionAdapter != null)
     {
         if (IsDropDownOpen)
         {
             SelectionAdapter.HandleKeyDown(e);
         }
         else
         {
             IsDropDownOpen = e.Key == Key.Down || e.Key == Key.Up;
         }
     }
 }