• Hi,

    I have a WP7 app which enables you to add an item (e.g. a password) - and each password has fields (e.g. password, category).

    On a panorama page I can list my passwords but I do not know how to group these passwords by category on the second panormaitem page.

    So - in order to group items that share the same category do I need to do this in the ListBox or in the DataTemplate? The snippet below basically lists the same category a number of times - how do I group it?

    Example code:

    <DataTemplate x:Key="PasswordBookItemTemplateEdit">
                <StackPanel Width="460" Margin="10,0">
                    <Grid Margin="0,20,0,0">
                        <TextBlock x:Name="CategoryTextBlock" 
    								   Text="{Binding Category}" 
    								   Foreground="{StaticResource PhoneForegroundBrush}" 
    								   FontSize="24" FontWeight="Bold"/>
     <controls:PanoramaItem Header="categories">
                            <ListBox Background="Transparent"
    					                ItemTemplate="{StaticResource PasswordBookItemTemplateEdit}" 
    					                ItemsSource="{Binding Entries}" 
    					                SelectionChanged="ListBox_SelectionChanged" />


    Wednesday, January 12, 2011 11:09 AM

All replies

  • Can I select distinct values in my linq query maybe - if so how?

    Current query:

    var entries = storage.LoadPasswordBook().OrderByDescending(x => x.CreatedDate);
    Wednesday, January 12, 2011 12:34 PM
  • Do you want to be able to only show the paswords of one certain category(ex: 1) or show all passwords grouped by category.

    If its the first just do:

    passwords.Where(pw => pw.CategoryID == 1).ToList() for example

    If it is the second just do:

    passwordgroups = passwords.GroupBy(pw => pw.CategoryID).ToList()

    You then use an ItemsControl(example: listbox) of any kind with the itemsource set to passwordgroups In the datatemplate of that Itemscontrol you can nest another itemscontrol that will contain all the passwords of that category. The datatemplate of that nested itemscontrol can just be a Textblock with the Text bound to the password.

    Do you understand or do you need a code example.

    Friday, January 14, 2011 4:44 AM
  • You could consider using the LongListSelector if you need to group displayed passwords by category. You should get the phone toolkit and check out the sample. It works like the contact list where you can collapse and expand the list by clicking the category headers.

    Friday, January 14, 2011 6:19 AM
  • thanks, still not working for me, I am trying to show a different list depending on the page, the "all" page works fine:

     if (menu == "all")
                    var entries = storage.LoadPasswordBook().OrderByDescending(x => x.CreatedDate);

    but the "categories" page does not, the error on Entries.AddRange is "The best overloaded method match for... .AddRange() has some invalid arguments:

     if (menu == "categories")
                    var entries = storage.LoadPasswordBook().GroupBy(x => x.Category).ToList();
    Tuesday, February 01, 2011 11:30 AM
  • Maybe you could put the entries into a PagedCollectionView?  That is easy to write grouping for and that grouping is implemented in the DataGrid.  Very cool, actually.

    Tuesday, February 01, 2011 11:54 AM