Last active
January 14, 2020 17:11
-
-
Save bjoerntx/186cbc9c2a946dddc9eb83bc643f26b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void ApplyMaskedString(RibbonItemCollection ribbonItems, dynamic data) | |
{ | |
// flatten data object in case of an array | |
if (data.GetType() == typeof(JArray)) | |
data = data[0]; | |
// loop through all ribbon items in the "insert merge fields" menu | |
foreach (Control ribbonButton in ribbonItems) | |
{ | |
// in case, the item is a drop-down, call ApplyMaskedString | |
// recursively with a new data object | |
if (ribbonButton is RibbonMenuButton) | |
{ | |
ApplyMaskedString( | |
((RibbonMenuButton)ribbonButton).DropDownItems, | |
data[ribbonButton.Text]); | |
} | |
// in case it is a merge field insert button | |
else if (ribbonButton is RibbonButton) | |
{ | |
// and it is not a separator or title | |
if (!ribbonButton.Name.StartsWith("TXITEM_")) | |
{ | |
// get the data from the first data row | |
var dataValue = data[ribbonButton.Text]; | |
if (dataValue == null) | |
continue; | |
if (dataValue.GetType() == typeof(JValue)) | |
{ | |
// change the actual text | |
ribbonButton.Text = dataValue.Value; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment