xamarin.forms - Onclicking listview cell only change content of clciked cell xamarin forms -


i using listview show contacts number in xamarin forms. on clicking cell want change content of particular cell. following code :

    lst_view.itemselected += async (object sender, selecteditemchangedeventargs e) =>         {              var con =(contact)e.selecteditem;             int index=contactlist.indexof(con);              if (con.is_selected)             {                 contactlist[index].is_selected = false;                 contactlist[index].img = "";              }             else{                  contactlist[index].is_selected = true;                 contactlist[index].img = "selected_checkbox.jpeg";              }              lst_view.itemtemplate = new datatemplate(typeof(contactsitemcell));          }; 

it working fine end giving new datatemplate thats on clicking cell whole listview redraw , annoying experience. want update cell , not whole listview. way on clicking changing image of cell through binding valueconverter. new xamarin form appreciated.

from code displayed, there simpler way without changing listview.itemtemplate. looks trying have selecteditem in listview change it's state "selected" state display checkbox image.

this should done utilizing onbindingcontext override in xamarin.forms.viewcell class. in override, can gain access bindingcontext of viewcell model of information displayed. in here should checking "is_selected" property , setting image listview.viewcell appropriate image stored in application.

to have changes updated in itemselected, need call onpropertychanged collection listview bound to. way changing selecteditem model correct, need ensure happens in source collection of data. calling onpropertychanged trigger xamarin.forms update viewcells bound source.

if needed have different viewcells displayed (not change selected image), shouldn't update itemtemplate of listview in itemselected event handler , shouldn't change itemtemplate ever. should create datatemplateselector. can provide datatemplate based on model object displayed.

i hope helps!

disclosure: work xamarin/microsoft


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -