Вопрос

I saw that a combobox itemsource can be binded in two main ways:

Direct binding

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

CollectionViewSource

<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}}"/>

Which is the difference between the two methods?

Это было полезно?

Решение

You can filters or sort with a CollectionViewSource.

I avoid them in favor of direct binding when ever I can.

With something like ObservableCollection or INotify it does not always get picked up by the view.

I have had cases where even when I refreshed the view it did not come thru.

I am not saying don't use CollectionViewSource but only use it when you need it.

Before I get attacked I am sure lots of people have never had a problem with CollectionViewSource.

How to: Sort and Group Data Using a View in XAML

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top