windows phone 7 - LongListSelector: Dynamic GridCellSize -
i have longlistselector , have following viewmodel
viewmodel: list<listdata> listdata: text image
i need cell size dynamic depending on listdata.
if text absent, i'll hide image , make gridcellsize = 50. if image present, gridcellsize should 250,250;
it'll this:
+---------+ +---------+ | text | | text | +---------+ +---------+ +---------+ +---------+ | text | | text | +---------+ +---------+ +---------+ +---------+ | | | | | | | | | image | | image | | | | | | | | | +---------+ +---------+ +---------+ +---------+ | | | | | | | | | image | | image | | | | | | | | | +---------+ +---------+
i tried changing gridcellsize using convertor seems gridcellsize needs constant longlistselector , applies elements.
is there way achieve this?
in 1 line can can bind grid height , width property double properties , can handle on logic..but have code logic.hope helps you..
so first made class of listdata in have made properties going use item of longlistselector ..here class..
public class listdata { public double height { get; set; } public double width { get; set; } public string text { get; set; } public string imagepath { get; set; } public visibility istextvisible { get; set; } public visibility isimagevisible { get; set; } }
now have created observablecollection longlistselector itemssource property going binded..
public observablecollection<listdata> listofdata { get; set; }
now have filled collection data..here data listdata class objects diffrent values of properties going reflect in longlistselector item..i have filled in mainpage constructor..
public mainpage() { initializecomponent(); listofdata = new observablecollection<listdata>(); listdata sd = new listdata(); sd.imagepath = "/assets/1.jpg"; sd.text = ""; sd.istextvisible = visibility.collapsed; sd.isimagevisible = visibility.visible; sd.height = 250; sd.width = 250; listdata sd1 = new listdata(); sd1.imagepath = "/assets/1.jpg"; sd1.text = "afhjkahfjkahjkghadgjkgjkv"; sd1.istextvisible = visibility.visible; sd1.isimagevisible = visibility.collapsed; sd1.height = 50; sd1.width = 50; listofdata.add(sd); listofdata.add(sd1); listofdata.add(sd); listofdata.add(sd1); listofdata.add(sd); listofdata.add(sd1); listofdata.add(sd); listofdata.add(sd1); this.datacontext = this; // sample code localize applicationbar //buildlocalizedapplicationbar(); }
now ready..i have data , datacontext of page set..so waht's remaining xaml page in linglistselector defined..here have binded every propety ..just sake of convinience..
<phone:longlistselector grid.row="0" itemssource="{binding listofdata}"> <phone:longlistselector.itemtemplate> <datatemplate> <grid height="{binding height}" width="{binding width}" > <textblock text="{binding path=text}" visibility="{binding istextvisible}"/> <image source="{binding path=imagepath}" visibility="{binding isimagevisible}" /> </grid> </datatemplate> </phone:longlistselector.itemtemplate> </phone:longlistselector>
here..all things being done..it requires logic now..hope helps you..
Comments
Post a Comment