2

我看到组合框 itemsource 可以通过两种主要方式绑定:

直接绑定

    <ComboBox Name="k" ItemsSource="{Binding Path=Mylist}"/>

集合查看源

<Window x:Class="WpfApplication25.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Window.Resources>
    <CollectionViewSource x:Key="list" Source="{Binding Items}"/>
</Window.Resources>

<ComboBox Name="k" ItemsSource="{Binding Source={StaticResource list}}"/>

这两种方法有什么区别?

4

1 回答 1

4

您可以使用 CollectionViewSource 进行过滤或排序。

我尽可能避免使用直接绑定。

使用 ObservableCollection 或 INotify 之类的东西并不总是被视图拾取。

我遇到过一些情况,即使我刷新了视图,它也没有通过。

我并不是说不要使用 CollectionViewSource,而是只在需要时使用它。

在我受到攻击之前,我相信很多人从来没有遇到过 CollectionViewSource 的问题。

如何:使用 XAML 中的视图对数据进行排序和分组

于 2014-04-09T21:17:59.583 回答