windows phone 7 - Every Album Art is the same -
i'm making music-player windows phone (c#). decided start app pivot-pages. 1 of them list of albums , there album art on left side of list. made class properties:
bitmapimage artwork; album alb;
and made viewmodelclass binding:
observablecollection<viewmodelhelper.albumhelper> albums = new observablecollection<viewmodelhelper.albumhelper>(); public observablecollection<viewmodelhelper.albumhelper> albums { { return albums; } } public albenviewmodel() { loadalbums(); } public void loadalbums() { using (medialibrary medialib = new medialibrary()) { bitmapimage bmp = new bitmapimage(); foreach (album alb in medialib.albums) { if (alb.hasart == true) { bmp.setsource(alb.getalbumart()); albums.add(new viewmodelhelper.albumhelper(bmp, alb)); } else { bmp.urisource = new uri("/gesture-music-player;component/images/noartwork.png", urikind.relative); albums.add(new viewmodelhelper.albumhelper(bmp, alb)); } } } }
when execute this, album arts same (which album art of last album in collection). if remove if condition, album arts image urisource how should be.
i don't understand why last image set albums.
you using 1 bitmapimage subsequently overwrite every time. that's why see last one.
you should move creation of bitmapimage inside for-loop:
foreach (album alb in medialib.albums) { bitmapimage bmp = new bitmapimage(); if (alb.hasart == true) { bmp.setsource(alb.getalbumart()); albums.add(new viewmodelhelper.albumhelper(bmp, alb)); } else { bmp.urisource = new uri("/gesture-music-player;component/images/noartwork.png", urikind.relative); albums.add(new viewmodelhelper.albumhelper(bmp, alb)); } }
Comments
Post a Comment