wpf数据绑定

时间:2021-12-29 07:18:37

标签:

 CollectionViewSource:可用于排序,但是他需要ObjectDataProvider作为数据源:
ollectionViewSource做为排序的数据源,首先将CollectionViewSource的Source 属性设置为 ObjectDataProvider的资源名称。然后通过设置CollectionViewSource.SortDescriptions属性,,指定排序字段和排序顺序 <CollectionViewSource x:Key="studentsView" Source="{Binding Source={StaticResource students}}">//students为ObjectDataProvider <CollectionViewSource.SortDescriptions> <scm:SortDescription PropertyName="Name" Direction="Ascending" /> <scm:SortDescription PropertyName="Age" Direction="Descending" /> </CollectionViewSource.SortDescriptions> </CollectionViewSource> Text="{Binding ElementName=listColor, Path=SelectedItem.Content, Mode=OneWay}"
WPF中把需要绑定同一个数据源的控件放在同一个容器控件内,然后将容器控件的 DataContext 设置为绑定源,容器内的控件的数据源绑定就可以不必再绑定,使用容器的数据源

wpf数据绑定