How would i assign distinct attribute value in a ComboBox datacontext?

dynamic-linq linq linq-to-sql wpf wpf-controls

Question

I want to use a ComboBox called categoryList to display every different Category.

<DataTemplate x:Key="CategoryTemplate">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding Path=Category}"/>
        </StackPanel>
    </DataTemplate>
...
 <ComboBox Name="catagoryList" VerticalAlignment="Top" SelectionChanged="categoryList_SelectionChanged" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" ItemTemplate="{StaticResource CategoryTemplate}"/>
...

coding used:

this.categoryList.DataContext = ldc.Books.Select(b => b.Category).Distinct();

But it's not functioning. How can I go about this? Or is there another option to do that? I'm grateful.

1
0
11/28/2012 2:23:16 PM

Accepted Answer

Zzz-5-Zzz is added to Zzz-9-ZZZ and is assigned toItemsSource .

this.categoryList.ItemSource = ldc.Books.Select(b => b.Category).Distinct().ToList();
0
11/28/2012 2:27:53 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow