public override void OnApplyTemplate() { base.OnApplyTemplate(); _listBox = (ListBox)GetTemplateChild("ListItems"); if (ItemsSource != null) { _collectionView = CollectionViewSource.GetDefaultView(ItemsSource); _collectionView.Filter = CustomerFilter; } _pupListBox = (Popup)GetTemplateChild("pupListBox"); _listBox.ItemsSource = _collectionView; _listBox.DisplayMemberPath = _viewElement; //_listBox.SelectionChanged += ListBox_SelectionChanged; _listBox.GotFocus += ListBox_GotFocus; _listBox.LostFocus += ListBox_LostFocus; _listBox.ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged; _searchBox = (TextBox)GetTemplateChild("SearchBox"); _searchBox.TextChanged += SearchBox_TextChanged; _searchBox.GotFocus += SearchBox_GotFocus; _searchBox.LostFocus += SearchBox_LostFocus; _pupListBox.Loaded += PupListBox_Loaded; _pupListBox.KeyUp += PupListBox_KeyUp; _pupListBox.KeyDown += PupListBox_KeyDown; _pupListBox.Opened += PupListBox_Opened; _searchBox.KeyDown += SearchtBox_KeyDown; EventManager.RegisterClassHandler(typeof(ListBoxItem), ListBoxItem.MouseLeftButtonDownEvent, new RoutedEventHandler(this.MouseLeftButtonDownClassHandler)); if (GroupNames != null && GroupNames.Count() > 0) { GroupNames.ToList().ForEach( x => _collectionView.GroupDescriptions.Add(new PropertyGroupDescription(x))); } UpdateStates(false); }