xaml - PrepareContainerForItemOverride works different in Desktop than in Mobile UWP -


i wanted change color of item of listview according data value. easy doing:

 <listview.itemcontainerstyle>          <style targettype = "listviewitem" >          < setter property="background" value="{binding eventtype, converter={staticresource eventtypetobackcolorconverter}}"  />  </listview.itemcontainerstyle> 

but thing uwp not support binding in setter properties. second attempt overriding preparecontainerforitemoverride of listview:

public class eventlistview : listview {     protected override void preparecontainerforitemoverride(dependencyobject element, object item)     {         base.preparecontainerforitemoverride(element, item);         var listviewitem = element listviewitem;         var ev = item eventtype;         if(ev.warning)            listviewitem.background = new solidcolorbrush(color.red);     } } 

the above code works fine running in pc windows 10 , uwp. colors in red items according underlying data. when run same app in windows mobile, @ beginning works fine, when scroll , scroll down, returning original view ok @ beginning, other items in red color.

what missing?

i not sure reason, following code works me:

public class eventlistview : listview {     protected override void preparecontainerforitemoverride(dependencyobject element, object item)     {         base.preparecontainerforitemoverride(element, item);         var listviewitem = element listviewitem;         var ev = item eventtype;         if(ev.warning)            listviewitem.background = new solidcolorbrush(color.red);         else            listviewitem.background = null;     } } 

i have added listviewitem.background = null


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -