c# - Windows Phone - LongListSelector grouped items by date and ordered by date -
i have basearticle
class has publisheddate
, grouping items days , after order them date , time. can grouping them day , works (i created property publisheddatestring
returns date in string):
public list<group<basearticle>> getarticlesgroups() { homecoming getitemgroups<basearticle>(articles, => a.publisheddatestring); } private static list<group<t>> getitemgroups<t>(ienumerable<t> itemlist, func<t, string> getkeyfunc) { ienumerable<group<t>> grouplist = item in itemlist grouping item getkeyfunc(item) g orderby g.key select new group<t>(g.key, g); homecoming grouplist.tolist(); }
i newbie in linq , don't know how can edit getitemgroups
method order items date after grouped. thanks
you're missing orderby
statement.
i don't have finish basearticle
class, going create simple creating song/artist class so:
public class sample_model { public sample_model(string artist, string song, string = "") { this.artist = artist; this.song = song; this.extra = extra; } public string artist { get; set; } public string song { get; set; } public string { get; set; } }
then going create list of sample_model doing this
class="lang-c# prettyprint-override">private observablecollection<sample_model> createdata() { observablecollection<sample_model> my_list = new observablecollection<sample_model>(); my_list.add(new sample_model("faith + 1", "body of christ", "a track")); my_list.add(new sample_model("faith + 1", "christ again", "a track")); my_list.add(new sample_model("faith + 1", "a night lord", "a track")); my_list.add(new sample_model("faith + 1", "touch me jesus", "a track")); my_list.add(new sample_model("faith + 1", "i found jesus (with else)", "a track")); my_list.add(new sample_model("faith + 1", "savior self", "a track")); my_list.add(new sample_model("faith + 1", "christ day", "a track")); my_list.add(new sample_model("faith + 1", "three times savior", "a track")); my_list.add(new sample_model("faith + 1", "jesus touched me", "a track")); my_list.add(new sample_model("faith + 1", "lord savior", "a track")); my_list.add(new sample_model("faith + 1", "i wasn't born 1 time again yesterday", "a track")); my_list.add(new sample_model("faith + 1", "pleasing jesus", "a track")); my_list.add(new sample_model("faith + 1", "jesus (looks kinda hot)", "a track")); my_list.add(new sample_model("butters", "what what", "b track")); // add together duplicate song our illustration my_list.add(new sample_model("faith + 1", "body of christ", "a track")); homecoming my_list; } // create our list observablecollection<sample_model> datasource = createdata();
at point have 2 artist (faith + 1 , butters).
we can query , grouping list of info artist name doing this
class="lang-c# prettyprint-override">var query = item in datasource grouping item item.artist artistgroup orderby artistgroup.key select artistgroup; foreach (var artistgroup in query) { // loop twice. 1 time butters , 1 time faith + 1 // order key artist name // butters first faith + 1 // songs not abc order, order same way inserted them list }
now original question! want list sort artist , each artist's song sorted well. must have orderby statement
// before grouping item.artist, sort item.song using `orderby` var query = item in svm.datasource orderby item.song grouping item item.artist artistgroup orderby artistgroup.key select artistgroup; foreach (var artistgroup in query) { // loop twice. 1 time butters , 1 time faith + 1 // order key artist name // butters first faith + 1 // time sub list of each artist have songs sorted // example, under faith + 1 see // "a night lord" follow // "body of christ" (twice) remember set 2 in }
c# linq windows-phone-8 windows-phone longlistselector
No comments:
Post a Comment