WPF DataContext vs ItemsSource Performance

Suppose we have an ItemControl that is source-constrained. Is there a performance difference between

ItemsControl.DataContext = resultSet;

      

and

ItemsControl.ItemsSource = resultSet;

      

(Both cases are correctly bound in XAML)

+2


source to share


1 answer


Well, the difference in performance doesn't really matter as the two lines do completely different things. DataContext is the object from which the local data bindings of the ItemsControl come from:

<ItemsControl Width={Binding Length} />

      



Take the Length property of the DataContext and bind it to the Width dependency property of the ItemsControl.

On the other hand, ItemSource is an IEnumerable object that must be iterated over to create child items inside the control. (Every object inside the ItemSource will become the DataContext of the created child)

+11


source







All Articles