How to change the default button label “No Prefere

2019-07-22 20:13发布

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? No Preference button with the default label

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条回答
欢心
2楼-- · 2019-07-22 21:10

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:

demo

查看更多
登录 后发表回答