Good day, gentlemen!

I can not solve the problem. Google does not save.

I have a control that I throw on the window. In control all code. He has:

  • Listbox
  • Textbox
  • FlowDocumentScrollViewer

What I do: when loading the control (in the constructor) I load the data into the property. CollectionViewSource is bound to this property, then grouping and sorting. ListBox is attached, actually, to CollectionViewSource.

I also search the ListBox with the TextBox and by the tab switching (by a certain parameter). And when I change the SelectedItem I pass the document to FlowDocumentScrollViewer (everything is fine with it so far).

For any of the above actions - hang 1-5 seconds. The most annoying hangup is when typing in a TextBox.

CollectionViewSource in control:

<UserControl.Resources> <!--Declaire CollectionView--> <converters:FirstLetterConverter x:Key="FLConverter" /> <converters:PlantToFlowDocumentConverter x:Key="PTFDConverter"/> <CollectionViewSource x:Key="plantsView" Source="{Binding Plants, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ContentViewer}}}" Filter="CollectionViewSource_Filter" > <!--Grouping--> <CollectionViewSource.GroupDescriptions> <PropertyGroupDescription PropertyName="Name" Converter="{StaticResource ResourceKey=FLConverter}"/> </CollectionViewSource.GroupDescriptions> <!--Sorting--> <CollectionViewSource.SortDescriptions> <componentModel:SortDescription PropertyName="Name" /> </CollectionViewSource.SortDescriptions> </CollectionViewSource> <DataTemplate x:Key="GroupingHeader"> <Border BorderBrush="#FFBABABA" BorderThickness="0,0,0,1" Margin="15,0,19,0" > <TextBlock Text="{Binding Name}" Foreground="#FFBABABA" /> </Border> </DataTemplate> </UserControl.Resources> 

TextBox and ListBox

 <TextBox x:Name="searchTextBox" Margin="12" TextWrapping="Wrap" Tag="Поиск" SelectionBrush="#FF55974D" ScrollViewer.CanContentScroll="True" Style="{DynamicResource SearchTextBoxStyle}" Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" /> <ListBox x:Name="plantsListBox" Style="{DynamicResource TelegramListBoxStyle}" ItemContainerStyle="{DynamicResource TelegramListBoxItemStyle}" ScrollViewer.HorizontalScrollBarVisibility="Hidden" Grid.Row="1" ItemsSource="{Binding Source={StaticResource ResourceKey=plantsView}}" ItemTemplate="{DynamicResource GroupingHeader}" HorizontalContentAlignment="Stretch" Margin="-5,0,-9,0" > <ListBox.GroupStyle> <GroupStyle HeaderTemplate="{StaticResource ResourceKey=GroupingHeader}" /> </ListBox.GroupStyle> </ListBox> 

Constructor:

 public ContentViewer() { InitializeComponent(); this.DataContext = this; tabControl.Loaded += delegate { var tmp = tabControl.Template; var chk = (CheckBox)tmp.FindName("PART_CheckBox", tabControl); chk.Click += delegate { if (tabControl.SelectedIndex == 1) { Plants = OriginalCollection.Where(x => x.IsFavorite == true).ToList<Plant>(); } }; }; Test(); } private void Test() { OriginalCollection = TestAdapter.GetData(); } 

Properties:

 private string _searchText = ""; private List<Plant> _plants; private List<Plant> _originalCollection; public List<Plant> OriginalCollection { get { return _originalCollection; } set { _originalCollection = value; Plants = _originalCollection; OnPropertyChanged("Plants"); } } public List<Plant> Plants { get { return _plants; } set { _plants = value; OnPropertyChanged("Plants"); } } public string SearchText { get { return _searchText; } set { _searchText = value; ((CollectionViewSource)this.Resources["plantsView"]).View.Refresh(); } } 

Filter (search)

 private void CollectionViewSource_Filter(object sender, FilterEventArgs e) { Plant item = e.Item as Plant; if (item.Name.ToUpper().Contains(_searchText.ToUpper())) { e.Accepted = true; } else { if (item.LatinName.ToUpper().Contains(_searchText.ToUpper())) { e.Accepted = true; } else { e.Accepted = false; } } } 

Filter by value:

 private void tabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { var i = (sender as TabControl).SelectedIndex; if (i == 0) { Plants = OriginalCollection; } else { Plants = OriginalCollection.Where(x => x.IsFavorite == true).ToList<Plant>(); } } 

UPD:

It turned out the GUI group hangs in the CollectionViewSource.

    0