Diagnosing Performance Problems with WPF ComboBox Data Binding

This morning I fought the โ€œslowโ€ WPF ComboBox and would like to know if anyone has any tips on debugging such a problem.

Say I have two ComboBoxes, A and B. When A changes, the elements in B also change. Each ComboBox has its own SelectedItem and ItemsSource data bindings as follows:

<ComboBox Grid.Column="1" ItemsSource="{Binding Names}" SelectedItem="{Binding CurrentName, Mode=TwoWay}" Margin="3" MinWidth="100" />
<ComboBox Grid.Column="1" Grid.Row="1" ItemsSource="{Binding SubNames}" SelectedItem="{Binding CurrentSubName, Mode=TwoWay}" Margin="3" MinWidth="100" />

Whenever the list in B needs to change, I do this by clearing the substitutions, and then re-adding the entries based on SelectedItem to A. This is because rewriting the sub-castle with the new one ObservableCollection<string>breaks the data binding.

Everything on one computer works as you expected. Select "A", then press "B" and new items will appear immediately. On another computer, when I do this, a pause of 5 seconds is performed before executing the ComboBox . The number of elements is the same. One of the differences is that on a slow machine in the background, there is hardware communication. I froze all these topics and it didnโ€™t help.

My biggest problem is that I cannot figure out where to even start looking. I need to see what the system does when I click on the ComboBox. I use data binding, so I canโ€™t put a breakpoint anywhere. I tried changing my subtitle ad from

public ObservableCollection<string> SubNames { get; set; }

to

private ObservableCollection<string> subnames_ = new ObservableCollection<string>();
public ObservableCollection<string> SubNames
{
  get { return subnames_; }
  set { subnames_ = value; }
}

getter setter, , , .

- , ? , - ComboBox, .

+5
1

, , ObservableCollection. , ItemsControl ICollectionView, ObservableCollection, ICollectionView.DeferRefresh().

, , ObservableCollection, DefaultView, ICollectionView, . ItemsControls collection.DefaultView. , , :

using (collection.DefaultView.DeferRefresh()) {
  collection. // add/remove/replace/clear etc
}

, , DeferRefresh(), .

, WPF TraceSource , ; , , , :

System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level = System.Diagnostics.SourceLevels.Verbose;

( , ).

+2

All Articles