Can an IGrouping enumeration be bound in XAML? And if so, what would the binding syntax look like?

I have a list of Customer objects, which I've grouped on Country.

var query = 
    from c in ctx.Customers group c by c.Country
    ...

query is now an enumeration of groups (IQueryable<IGrouping<string, Customer>>), where each item of thie enumeration defines a group (IGrouping<string, Customer>).

I understand that IGrouping is: the key of the group (Country in my example) and the items grouped by Country. It's straightforward how to iterate through this data with a foreach statement, but what I need help on is how to bind the grouping in XAML.

I would like to use nested <ItemsControl> controls, the outer one to list the Country names and an inner one to iterate through the grouped customers for that country. By problem lies with binding to an IGrouping group.

Can it be done and if so, would the binding syntax look like?

Answers


You can use a HierarchicalDataTemplate. For instance, if you want to bind a TreeView to the result, you can do something like that :

<TreeView ItemsSource="{Binding Groups}">
    <TreeView.ItemTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding}">
            <TextBlock Text="{Binding Key}" />
        </HierarchicalDataTemplate>
    </TreeView.ItemTemplate>
</TreeView>

Need Your Help

Spynner downloads a zero-byte .jpg with browser.download(url, filename) - Python, PHP

php python beautifulsoup spynner

Here is the code I have tried. The files are 0 bytes. I've also set imagedata=br.download(...) and it reports 0 for len(). I've been at this for hours... any ideas?