c# - Disable button when clicked and make other buttons enabled -
i have 3 buttons in wpf window best way disable button when clicked , make other 2 button enabled
<button name="initialzebutton" width="50" height="25" margin="460,0,0,0" horizontalalignment="left" verticalalignment="center" click="initialzebutton_click" content="start" cursor="hand" /> <button name="uninitialzebutton" width="50" height="25" margin="0,0,64,0" horizontalalignment="right" verticalalignment="center" click="uninitialzebutton_click" content="stop" cursor="hand" /> <button name="loadbutton" width="50" height="25" margin="0,0,9,0" horizontalalignment="right" verticalalignment="center" click="loadbutton_click" content="load" cursor="hand" /> now use way in each button :(
private void uninitialzebutton_click(object sender, routedeventargs e) { this.uninitialzebutton.isenabled = false; if (!this.initialzebutton.isenabled) { this.initialzebutton.isenabled = true; } if (!this.loadbutton.isenabled) { this.loadbutton.isenabled = true; } }
what definition of 'best way'? quick , few lines of code or elegant or..
several ways come mind:
- use mvvm light: 1 relaycommand 3 buttons, 3 dependency objects (properties in viewmodel) isenabled set false, set isenabled true button clicked (which sent parameter in relaycommand).
- use booleanconverters/booleaninverterconverters on isenabled property.
- restyle radiobutton button, replace 3 buttons radiobutton group. when 1 radiobutton selected, other ones deselected, style them disabled. prevent deselected items being clicked.
regards,
michel
Comments
Post a Comment