c# - In WPF how can I control whether another button clicked -
i want determine button clicked in wpf. wrote same code below, when clicked button animation works after when clicked same button animation work else block. want control if button clicked , want work of else block.
int = 0; private void btndashboard_click(object sender, routedeventargs e) { // btndashboard.click += btndashboard_click; // button btnsender = (button)sender; if (i%2==0) { doubleanimation anim = new doubleanimation(250, 1470, new duration(timespan.frommilliseconds(300))); btndashboard.beginanimation(frameworkelement.widthproperty, anim); ((applicationshell)app.current.mainwindow).showpages(new ucdashboardindicatorview()); i++; } else { doubleanimation anim = new doubleanimation(1470, 250, new duration(timespan.frommilliseconds(300))); btndashboard.beginanimation(frameworkelement.widthproperty, anim); base.onapplytemplate(); i++; } }
how can control it?
if want use same click handler 2 buttons, try this:
private void btndashboard_click(object sender, routedeventargs e) { button btnsender = sender button; if(btnsender.name == "btn1") { //code button1 } else { //code button2 } }
also make sure each button has name property set in xaml can access in code behind. in xaml:
<grid> <button name="btn1" click="btndashboard_click"/> <button name="btn2" click="btndashboard_click"/> </grid>
Comments
Post a Comment