android - Can I reorder the ListView items on the Run in Xamarin.Forms? -


since listview has eventhandler childrenreordered can reorder items in list view during runtime??

with of example here have created similar view in image given below. can suggest way reorder listview on run if possible. remove listview parent , create again, suggestion workaround reordering items helpful.

enter image description here

code:

using system; using system.linq; using system.collections.generic; using xamarin.forms;  namespace orderby { class listviewdemopage : contentpage {     list<sourceitem> people = null;      class sourceitem     {         public sourceitem(string item)         {             this.item = item;         }          public string item { private set; get; }     };      public listviewdemopage()     {          // define data.         people = new list<sourceitem>         {             new sourceitem("abigail"),             new sourceitem("bob"),             new sourceitem("cathy"),             new sourceitem("david"),             new sourceitem("eugenie"),             new sourceitem("freddie"),             new sourceitem("greta"),             new sourceitem("harold"),             new sourceitem("irene"),             new sourceitem("jonathan"),             new sourceitem("kathy"),             new sourceitem("larry"),             new sourceitem("monica"),             new sourceitem("nick"),             new sourceitem("olive"),             new sourceitem("pendleton"),             new sourceitem("queenie"),             new sourceitem("rob"),             new sourceitem("sally"),             new sourceitem("timothy"),             new sourceitem("uma"),             new sourceitem("victor"),             new sourceitem("wendy"),             new sourceitem("xavier"),             new sourceitem("yvonne"),             new sourceitem("zachary")         };          // create listview.         listview listview = new listview         {             // source of data items.             itemssource = people,             widthrequest = 300,             heightrequest = 350,              itemtemplate = new datatemplate(() =>                 {                     // create views bindings displaying each property.                     label itemlabel = new label();                     itemlabel.widthrequest = 200;                     itemlabel.setbinding(label.textproperty, "item");                      image = new image();                     up.source = imagesource.fromfile("up_arrow.png");                     up.backgroundcolor = color.transparent;                     up.widthrequest = 25;                     up.heightrequest = 25;                      image down = new image();                     down.source = imagesource.fromfile("down_arrow.png");                     down.backgroundcolor = color.transparent;                     down.widthrequest = 25;                     down.heightrequest = 25;                      // return assembled viewcell.                     return new viewcell                     {                         view = new stacklayout                         {                             padding = new thickness(0, 5),                             orientation = stackorientation.horizontal,                             children =                              {                                 itemlabel,                                 up, down,                              }                             }                     };                 })         };          // accomodate iphone status bar.         this.padding = new thickness(10, device.onplatform(20, 0, 0), 10, 5);          // build page.         this.content = new stacklayout         {             verticaloptions = layoutoptions.centerandexpand,             horizontaloptions = layoutoptions.center,             children =              {                 listview             }             };     }   } } 

thanks in advance

yes can.

you need use observablecollection instead of list<>

something along lines of...

observablecollection<sourceitem> source = new ... // class property or field  viewcell viewcell = new ... ... image down = new... down.gestureregognizers.add(new tapgesturerecognizer(()=>movedown(viewcell.bindingcontext sourceitem)));  // missing bunch of checks below such i==0 private void movedown(sourceitem item){   int = source.indexof(item);   source.removeat(i);   source.insert(item, i-1); } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -