I’ve got the following code that works well :
<Viewbox.Resources>
<CollectionViewSource x:Key="viewSource"
Source="{Binding Path=SelectionList}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Description" />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</Viewbox.Resources>
<ComboBox ItemsSource="{Binding Source={StaticResource ResourceKey=viewSource}}"/>
I would like to put my CollectionViewSource directly in my ComboBox without using any resource like that :
<ComboBox SelectedItem="{Binding Path=Value, Mode=TwoWay}">
<ComboBox.ItemsSource>
<Binding>
<Binding.Source>
<CollectionViewSource Source="{Binding Path=SelectionList}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Description" />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</Binding.Source>
</Binding>
</ComboBox.ItemsSource>
</ComboBox>
But this way my ComboBox is always empty, and I get the following binding error :
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement
or FrameworkContentElement for target element.
BindingExpression:Path=SelectionList; DataItem=null; target element is
‘CollectionViewSource’ (HashCode=1374711); target property is ‘Source’
(type ‘Object’)
Does anyone know how could I do it ?
Nicolas, although this is not an answer to your question because it still uses resources, you could put the CollectionViewSource inside the ComboBox by defining it in its local resource dictionary: