Aracılığıyla paylaş


Nasıl Yapılır: Veri Koleksiyonunun Varsayılan Görünümünü Alma

Views allow the same data collection to be viewed in different ways, depending on sorting, filtering, or grouping criteria. Every collection has one shared default view, which is used as the actual binding source when a binding specifies a collection as its source. This example shows how to get the default view of a collection.

Örnek

To create the view, you need an object reference to the collection. This data object can be obtained by referencing your own code-behind object, by getting the data context, by getting a property of the data source, or by getting a property of the binding. This example shows how to get the DataContext of a data object and use it to directly obtain the default collection view for this collection.

      myCollectionView = CType(CollectionViewSource.GetDefaultView(rootElem.DataContext), CollectionView)
myCollectionView = (CollectionView)
    CollectionViewSource.GetDefaultView(rootElem.DataContext);

In this example, the root element is a StackPanel. The DataContext is set to myDataSource, which refers to a data provider that is an ObservableCollection<T> of Order objects.

<StackPanel.DataContext>
  <Binding Source="{StaticResource myDataSource}"/>
</StackPanel.DataContext>

Alternatively, you can instantiate and bind to your own collection view using the CollectionViewSource class. This collection view is only shared by controls that bind to it directly. For an example, see the How to Create a View section in the Veri Bağlama Genel Bakış.

For examples of the functionality provided by a collection view, see Nasıl Yapılır: Görünümde Veri Sıralama, Nasıl Yapılır: Görünümde Veri Filtreleme, and Nasıl Yapılır: Veri CollectionView içindeki Nesneler aracılığıyla Gezinme.

Ayrıca bkz.

Görevler

Nasıl Yapılır: XAML İçerisinde Bir Görüntü Kullanarak Verileri Sıralama ve Gruplama

Diğer Kaynaklar

Veri Bağlama Nasıl Yapılır Konuları