c# - Adding Slider values from DataTemplate in ListView -
i created datatemplate containing: textblock , slider (x:name="_score") in horizontal stackpanel. textblock refers new observablecollection, class category contains string textblock text. listview 7 items uses datatemplate, there 7 sliders in window.
every time change value of slider _score, want update textblock total sum of slider's values. different sliders have different values selected user. have event handler valuechanged="_slidscore."
can differentiate sliders 1 add total value each slider?
<page.resources> <!-- todo: delete line if key appname declared in app.xaml --> <x:string x:key="appname">questionnaire</x:string> <datatemplate x:key="_itemtemplate"> <border borderbrush="gainsboro" borderthickness="4"> <stackpanel orientation="horizontal"> <textblock margin="8,0,8,0" fontsize="18" width="200" verticalalignment="center" textwrapping="wrap" text="{binding crit}"/> <stackpanel> <slider margin="10,0,10,0" verticalalignment="center" value="0" maximum="5" minimum="0" tickfrequency="1" tickplacement="outside" x:name="_score" width="641" valuechanged="_slidscore"/> <stackpanel orientation="horizontal" horizontalalignment="center"> <textblock verticalalignment="center" text="rating: " fontsize="24"/> <textblock verticalalignment="center" margin="10,0,0,0" text="{binding value, elementname=_score}" fontsize="24"/> </stackpanel> </stackpanel> </stackpanel> </border> </datatemplate> </page.resources> .... in main grid: <border grid.row="1" borderbrush="red" borderthickness="5"> <textblock text="how have you..." textwrapping="wrap" fontweight="bold" fontsize="20" verticalalignment="center"/> </border> <listview x:name="_listview" grid.row="2" itemtemplate="{staticresource _itemtemplate}" selectionmode="none" horizontalcontentalignment="stretch"/> <textblock grid.row="2" grid.column="1" x:name="_result" fontsize="70"/> ... in codebehind file //list populate textblock in datatemplate _listview.itemssource = new observablecollection<category> { new category{crit = "1231231231231231231?"}, new category{crit = "asdfafhadgfjargfjagj?"}, new category{crit = "qerklhjyahkildfjkladnhjkla?"}, new category{crit = "13490p76812390-qhjsedhjklg?"}, new category{crit = "asdfasdgq3e45uq345u?"}, new category{crit = "q3490u8yq38945yasdjiofhj?"}, new category{crit = "13406923789045whjioerghjkla?"} }; class category { public string crit { get; set; } }
i discovered own answer:
int total = 0; private void _slidscore(object sender, rangebasevaluechangedeventargs e) { total -= (int)e.oldvalue; total += (int)e.newvalue; _result.text = total.tostring(); }
_slidscore event handler slider. output int total textblock _result.
Comments
Post a Comment