views:

26

answers:

1

Is it appropriate to only set the Visibility-property of an unused virtualizing list-control to Collapsed.

I have a ViewModel that implements IEnumerable<SomeType> and have some virtualizing list-controls that bind directly to the ViewModel (declared in markup). At a time always only one of the list controls is visible.

Is it appropriate to set only the Visibility of the unused lists to collapsed, because in this case no items will be produced for the invisible list-controls or should I better clear and set the ItemsSource-property?

I’m aware that there is an overhead because the two or more controls track the collection changes (INotifyCollectionChanged) but IMO this overhead is negligible. Am I right?

+1  A: 

You are correct. It's possible that clearing your collections could actually cause a bigger performance hit than leaving them alone. Although the control will populate its Items collection from the bound source collection and connect handlers there won't be any of the rendering and creation of child elements that is almost always the much slower part of binding to collections. Once it's set to Collapsed it doesn't exist from the perspective of the rendering engine.

John Bowen