vsto - Cannot enable a Ribbon button programmatically -
i developed vsto 4 add-in excel. works perfect, however, have button placed in custom tab of ribbon control disabled.
after clicked other ribbon button in custom tab, need enable disabled button.
i tried with:
btncancelar.visible = true;
in click event of button, button not shown. strange thing when debugging, still not appear, if messagebox shown, button visible @ last.
i don't understand behaviour. how can enable or disable ribbon button dynamically code?
i'm not sure language used in project, guess can tranform own language used. i'll show example here in c#:
first need implement called callback function in ribbonxml definition:
<button id="buttonsomething" label="content" size="large" getvisible="enablecontrol"/>
then next step implement callback function:
public bool enablecontrol(iribboncontrol control) { return true; // visible ... false = invisible }
vsto trigger getvisible callback , depending on return value enable or disable visible state (don't forget remove visible property ribbonxml, otherwise callback not triggered)
in case of ribbon designer need make sure click signature correct, easies way double clicking button on ribbon designer. create click method you, instance:
i created ribbon ribbon designer , added 2 buttons. double clicked first button empty method below, , added code.
private void button1_click(object sender, ribboncontroleventargs e) { // toggle button visibility , make sure button enabled // visible (obviously) makes visible, while enabled grayed if // false. don't need enabled default, // demo purposes button2.visible = !button2.visible; button2.enabled = button2.visible; // force ribbon invalidate ... this.ribbonui.invalidate(); // long running proces }
this worked me, if doesn't work please provide more details of coding.
Comments
Post a Comment