c# - How to retrieve the selected group in a LongListSelector? -


i using longlistselector showing groups contact (one contact can belong multiple groups)

class group {     public string name { get; set; } }  class contact {     public string name { get; set; }     public list<group> groups { get; set; } } 

i use code below build itemssource longlistselector

public list<keyedlist<group, contact>> groupedcontacts  {           {         list<group> groups = ...;         list<contact> contacts = ...;          list<keyedlist<group, contact>> result                  = new list<keyedlist<group, contact>>();         foreach (group gr0up in groups)         {             var temp = c in contacts c.groups.contains(gr0up) select c;             list<contact> groupedcontacts = new list<contact>(temp);              result.add(new keyedlist<group, contact>(gr0up, groupedcontacts));         }          return result;     } } 

as can see code above, single contact object can used in several groups. handle selectionchanged event , can selected contact can't information selected group.

is there 'standard' possibility know, group has been selected?

update

<grid>     <grid.resources>         <datatemplate x:key="groupheader">             <grid margin="3,3" width="480" height="90" horizontalalignment="stretch"                     hold="groupdelete" tag="{binding key.name}">                 <grid.columndefinitions>                     <columndefinition width="auto"/>                     <columndefinition width="*"/>                     <columndefinition width="auto"/>                     <columndefinition width="auto"/>                     <columndefinition width="20"/>                 </grid.columndefinitions>                 <textblock grid.column="0" text="{binding key.name}"/>             </grid>        </datatemplate>        <datatemplate x:key="itemtemplate">             <stackpanel height="128" width="128" orientation="vertical">                 <grid>                     <image width="102" height="102" verticalalignment="top" horizontalalignment="left" stretch="uniformtofill">                         <image.source>                             <bitmapimage urisource="/assets/contact_template.png" createoptions="backgroundcreation"/>                         </image.source>                     </image>                     <image width="36" height="36" verticalalignment="top" horizontalalignment="right"                             margin="10,5,35,0"                             source="/assets/delete_contact.png"/>                 </grid>                 <textblock text="{binding name}" foreground="black" verticalalignment="top"/>             </stackpanel>         </datatemplate>     </grid.resources>      <phone:longlistselector name="contactslist"                         itemssource="{binding groupedcontacts}"                         itemtemplate="{staticresource itemtemplate}"                                              groupheadertemplate="{staticresource groupheader}"                         style="{staticresource contactslonglistselectorstyle}"                         selectionchanged="contactslist_selectionchanged"                         scrollviewer.horizontalscrollbarvisibility="disabled"                          scrollviewer.verticalscrollbarvisibility="disabled"/> </grid> 

keyedlist implementation:

public class keyedlist<tkey, titem> : list<titem> {     public tkey key { protected set; get; }      public keyedlist(tkey key, ienumerable<titem> items)         : base(items)     {         key = key;     }      public keyedlist(igrouping<tkey, titem> grouping)         : base(grouping)     {         key = grouping.key;     } } 

in contactslist_selectionchanged(sender,e): e.addeditems[0] should give group/value pair.

update: receive key/value pair in selectionchanged(), each list item of longlistselector needs key/value pair.

here's walkthrough longlistselector (it's specialized in groups strings , calculated value, can made more generic): http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj244365%28v=vs.105%29.aspx

so example's addressbook class

public class longlistgroupentry {     public group key;     public contact value; } 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -