public AutoCompleteItem(AutoCompleteContext context)
        {
            _context = context;

            this.TextBlock = new TextBlock();

            _currentSearchPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(AutoCompleteContext.CurrentSearchProperty, typeof(AutoCompleteContext));
            _currentSearchPropertyDescriptor.AddValueChanged(_context, _context_CurrentSearchChanged);
        }
        public AutoCompleteTextBox()
        {
            InitializeComponent();

            _context = new AutoCompleteContext();

            spRoot.DataContext = this;

            lstAutoCompleteItems.ItemsSource = _items;

            DependencyPropertyDescriptor.FromProperty(TextBoxBase.IsSelectionActiveProperty, typeof(TextBoxBase)).AddValueChanged(
                txtInput,
                (sender, e) =>
            {
                SetValue(IsSelectionActivePropertyKey, txtInput.IsSelectionActive);
            });

            txtInput.SelectionChanged +=
                (sender, e) =>
            {
                RaiseEvent(new RoutedEventArgs(SelectionChangedEvent));
            };

            string raiseTextChangedForValue = null;

            DependencyPropertyDescriptor.FromProperty(TextProperty, typeof(AutoCompleteTextBox)).AddValueChanged(
                this,
                (sender, e) =>
            {
                string newText = this.Text;

                if (txtInput.Text != newText)
                {
                    raiseTextChangedForValue = newText;
                    txtInput.Text            = newText;
                    raiseTextChangedForValue = null;
                }
            });

            txtInput.TextChanged +=
                (sender, e) =>
            {
                string newText = txtInput.Text;

                bool isChange = (this.Text != newText);
                bool isValueFromOuterProperty = (newText == raiseTextChangedForValue);

                if (isChange || isValueFromOuterProperty)
                {
                    if (isChange)
                    {
                        this.Text = newText;
                    }

                    RaiseEvent(new TextChangedEventArgs(TextChangedEvent, e.UndoAction, e.Changes));
                }
            };

            this.SetBinding(
                SelectionBrushProperty,
                new Binding()
            {
                Source = txtInput,
                Path   = new PropertyPath(TextBox.SelectionBrushProperty),
            });

            this.SetBinding(
                SelectionOpacityProperty,
                new Binding()
            {
                Source = txtInput,
                Path   = new PropertyPath(TextBox.SelectionOpacityProperty),
            });
        }