wpf - How to make a TextBlock work like a score counter in C# XAML -


<canvas x:name="layoutroot" background="white">     <image source="level1.jpg"  name="bg" width="640" height="480"            canvas.top="10" canvas.left="50"/>     <textblock name="score">scorehere</textblock>  </canvas> 
void compositiontarget_rendering(object sender, eventargs e) {              if (detectcollisionleft(mycat, myzero))     {         layoutroot.children.remove(myzero);                         } } 

what have when cat in game collides number 0 number disappears. how can textblock in xaml display number increases every time number collected.

thank you

as understand problem statement, want update score every time collision detected. if update textblock.text property update score.

void compositiontarget_rendering(object sender, eventargs e) {              if (detectcollisionleft(mycat, myzero))     {         if(layoutroot.children.contains(myzero))         {             layoutroot.children.remove(myzero);              //update score score = previousscore + 1             int scoreasint;             if(int32.tryparse(score.text, numberstyles.integer, cultureinfo.currentculture, out scoreasint) != null)             {                 scoreasint = scoreasint + 1;                 score.text = scoreasint.tostring(cultureinfo.currentculture);             }         }     } } 

note have consider scenario in score becomes large integer range. in case can either reset score or use larger type long score.


Comments