问题
Is there a way to modify the default "No Preference" label of the button when updating the user inputs to read e.g. "I don't want to change anything." without introducing a new Resources.*.resx file?
I tried all templates that allow changing such literals but I found no one that could achieve this. TemplateUsage.NoPreference can be used to change only the value of an optional field, not the button label.
回答1:
You can do it by overriding the Template
value in your FormFlow.
Here is an example based on the Microsoft.Bot.Sample.SimpleSandwichBot:
public static IForm<SandwichOrder> BuildForm()
{
var formBuilder = new FormBuilder<SandwichOrder>()
.Message("Welcome to the simple sandwich order bot!");
var noPreferenceStrings = new string[] { "Nothing" };
// Set the new "no Preference" value
formBuilder.Configuration.Templates.Single(t => t.Usage == TemplateUsage.NoPreference).Patterns = noPreferenceStrings;
// Change this one to help detection of what you typed/selected
formBuilder.Configuration.NoPreference = noPreferenceStrings;
return formBuilder.Build();
}
Demo capture:
来源:https://stackoverflow.com/questions/48060923/how-to-change-the-default-button-label-no-preference-in-formflow