Combobox performance after changing ItemsSource

I have a datagrid with a column of comboboxes defined like this:

<DataGridTemplateColumn x:Name="AssortmentQualitySettingsDataGridColumn" Header="Kvaliteter">
<DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <ComboBox ItemsSource="{Binding Path=QualityInfoAssortmentCollection}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <CheckBox IsChecked="{Binding Path=ActiveQuality}"></CheckBox>
                        <TextBlock Text="{Binding Path=QualityName}" IsEnabled="False"></TextBlock>
                    </StackPanel>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
    </DataTemplate>
</DataGridTemplateColumn.CellTemplate>

The ItemsSource is an ObservableCollection of objects. The texts for the textbox in the combobox is however editable in another datagrid and put in another ObservableCollection called QualityItemCollection, and to get the comboboxes in the grid above updated I have an event on the datagrid that fires when that collection is changed. This even causes the QualityInfoAssortmentCollection to be re-read (the combobox needs to be set again also, so there is some looping to get it working).

Now, what happens is that the first time when data is loaded, everything is nice and dandy, however, when the event updating QualityInfoAssortmentCollection has fired the comboboxes above takes 5-7 seconds to drop down when trying to get into it. The refresh itself I have timed and it takes less than a tenth of a second to do. The combobox doesn't have more than 8-10 rows and there no difference trying to use a virtualizingstackpanel as suggested elsewhere. The datagrid displaying it has around 10 rows so it's not even close to any enormous amounts of data that needs to be shuffled.

Edit: More explanation about not being able to use the defining QualityItemCollection. The QualityItemColletion is the same for all items in the above datagrid, but the information about which checkboxes should be checked is set per item in the grid above. Therefore I make a copy of QualityItemCollection into QualityItemAssortmentCollection which also has a bool for the checkbox. There might be a better way to do this?

Edit 2: Tried the WPF profiler now and it locks up just as the program does and doesn't display anything during the time the program is doing strange things. However, it turns it's something Visual Studio does, since if I run the program alone and not through Visual Studio there is no delay. Yay.


Problem was with the VS debugger. It for some reason makes the combobox excruciatingly slow.


So, fix it?

when the event updating QualityInfoAssortmentCollection has fired the comboboxes above takes 5-7 seconds to drop down when trying to get into it.

Where does it spend time? It is not like there are no profilers around. It is totally possible that this is WPF related, in which case this link:

http://msdn.microsoft.com/en-us/library/aa969767.aspx

also gets you staretd with a WPF level profiler (ie you can see where WPF spends the time, which may be some mistake in some WPF definitions).

It is also possible you send too many nonsensible update events (ou should always c hange whether a value HAS vchanged before sending an update notification). So, an upate may updatea property to teh same value triggering another update. A profiler will allow you to find these occurances.

Noone here can help yuo - without code etc. But a profiler should make it QUITE obvious where the time is spent.

链接地址: http://www.djcxy.com/p/41262.html

上一篇: ComboBox花费太长时间才能打开(COMException错误)

下一篇: 更改ItemsSource后的组合框性能