Reputation: 9
XML code:
<checkBox
id="Fill"
label="F"
getPressed="CheckedByDefault"
/>
C# code:
public void CheckedByDefault(Office.IRibbonControl control)
{
RibbonCheckBox ch = control;
ch.Checked = true;
}
I am not able to declare the RibbonCheckbox in this way and, therefore, not able to access and modify its "Checked" property.
Any ideas??
Upvotes: 0
Views: 922
Reputation: 1
a bit late, but here is the answer :
Ribbon xml:
<checkBox
id="Fill"
label="F"
getPressed="CheckedByDefault"
/>
C#:
public bool CheckedByDefault(Office.IRibbonControl control)
{
return true;
}
It will check by default the checkbox.
Also, you can't do this:
RibbonCheckBox ch = control;
Because what you get with the method is a control. To get a "RibbonCheckBox", you need to create it with the factory. Read this: https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.tools.ribbon.ribbonfactory?view=vsto-2022
I hope it will help you :)
Upvotes: 0
Reputation: 386
I know this is an old post but I was looking for a good example of how to do this and was unable to find a good example. I finally figured it out and thought I'd post to help someone else in the future.
You could set the value in the XML for the checkbox control as follows-
enabled="true"
Another option is to set the checkbox dynamically by setting a property to true or false to toggle it on or off as follows-
public static string YourPropertyValue
{
get;
set;
}
public bool CheckedByDefault(IRibbonControl ribbon)
{
//Check Checkbox
if (YourPropertyValue == true)
{
return true;
}
//Uncheck Checkbox
else
{
return false;
}
}
Upvotes: 0
Reputation: 9
Solved:
C# code:
public void CheckedByDefault(Office.IRibbonControl control)
{
return true;
}
Upvotes: 0