c# - Change image of a button that is on an element of a LongListSelector -
i have longlistselector:
<phone:longlistselector x:name="listamensajestablon" itemssource="{binding mensajes}" itemtemplate="{staticresource mensajestablondatatemplate}" selectionchanged="mensajetablonselected"/>
with itemtemplate:
<datatemplate x:key="mensajestablondatatemplate"> <grid> <button maxheight="85" maxwidth="95" minheight="85" minwidth="95" grid.column="1" horizontalalignment="right" verticalalignment="center" click="button_click" borderbrush="transparent"> <button.content> <image x:name="imagenfav" maxheight="75" maxwidth="75" minheight="75" minwidth="75" source="{binding userfav, converter={staticresource booltoheart}}" verticalalignment="center" horizontalalignment="center"/> </button.content> </button> </grid> </datatemplate>
this code-behind:
private void button_click(object sender, routedeventargs e) { botonfavpulsado = true; botonamor = (button)sender; } private void mensajetablonselected(object sender, selectionchangedeventargs e) { if(botonfavpulsado) { var myitem = ((longlistselector)sender).selecteditem mensajetablon; if(botonamor!=null) { if (myitem.userfav) { botonamor.content = new image { source = new bitmapimage(new uri("icons/heart.red.png", urikind.relative)) }; } else { botonamor.content = new image { source = new bitmapimage(new uri("icons/heart.white.png", urikind.relative)) }; } } botonfavpulsado = false; } }
i want when press button inside element of longlistselector change picture . first time press button enters in function button_click , enters in function mensajetablonselected function , change image (good). problem second time press same button entering in function button_click function , not enter in function mensajetablonselected
resume : togglebutton in longitemselector working first time not second one
problem solved:
private void mensajetablonselected(object sender, selectionchangedeventargs e) { if (((longlistselector)sender).selecteditem != null) if(botonfavpulsado) { var myitem = ((longlistselector)sender).selecteditem mensajetablon; if(botonamor!=null) { if (myitem.userfav) { botonamor.content = new image { source = new bitmapimage(new uri("icons/heart.red.png", urikind.relative)) }; } else { botonamor.content = new image { source = new bitmapimage(new uri("icons/heart.white.png", urikind.relative)) }; } } botonfavpulsado = false; //unselect item ((longlistselector)sender).selecteditem = null; } }
this solution have problem, function mensajetablonselected called again.
Comments
Post a Comment