c# - Change background button color on click -


i'm developing windows phone 8 app , have 2 buttons. once click on first 1 it's color changed, when click on second 1 , color changed color of first button not set default. can't access first button click event of second one. how can highlight 1 button , set color of 1 default on click?

edit: here can't access second button within first event handler.

private void firstbutton_click(object sender, routedeventargs e) {     (sender button).background = new solidcolorbrush(colors.green);  }  private void secondbutton_click(object sender, routedeventargs e) {     (sender button).background = new solidcolorbrush(colors.green);  } 

why can't access first button second one? similar this:

private void firstbutton_click(object sender, routedeventargs e) {     (sender button).background = new solidcolorbrush(colors.green);      secondbutton.background = new solidcolorbrush(colors.lightgray); }  private void secondbutton_click(object sender, routedeventargs e) {     (sender button).background = new solidcolorbrush(colors.green);     firstbutton.background = new solidcolorbrush(colors.lightgray); } 

and reusability perhaps throw in method:

private void setbuttoncolor(button todefaultcolor, button togreencolor) {     togreencolor.background = new solidcolorbrush(colors.green);     todefaultcolor.background = new solidcolorbrush(colors.lightgray); }  private void secondbutton_click(object sender, routedeventargs e) {     setbuttoncolor(firstbutton, (sender button)); } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -