[英]Customize/modifiy prompt text of a class property in bot framework
I have below field in my class 我班上有下面的田野
[Prompt("Please enter conference title/subject")]
public string confname { get; set; }
I want to modify text "Please enter conference title/subject" dynamically. 我想动态修改文本“请输入会议标题/主题”。 Actually, I want to pass URL along with prompt text, how to achieve this?
实际上,我想将URL和提示文本一起传递,如何实现呢?
I have tried below code, but don't know how to pass modified text in promptattribute 我已经尝试过下面的代码,但是不知道如何在提示属性中传递修改后的文本
public static IForm<ConferenceBooking> BuildForm()
{
return new FormBuilder<ConferenceBooking>().Message("Tell me meeting details!")
.Field(nameof(confname), prompt: new PromptAttribute("please enter confname"))
}
You can use the SetDefine(delegate)
to dynamically change the attributes of a field. 您可以使用
SetDefine(delegate)
动态更改字段的属性。 The delegate has two parameters: the state of the form and the field it's binded too. 委托有两个参数:表单的状态和它绑定的字段。 The delegate should always return true.
委托应始终返回true。
Here is an example: 这是一个例子:
[Serializable]
public class SimpleForm
{
public string Name;
[Numeric(1, 5)]
[Prompt("Your experience with the form")]
public float? Rating;
public static IForm<SimpleForm> BuildForm()
{
return new FormBuilder<SimpleForm>()
.Field(nameof(Rating))
.Field(new FieldReflector<SimpleForm>(nameof(Name))
.SetDefine(DefinitionMethod))
.Build();
}
private static async Task<bool> DefinitionMethod(SimpleForm state, Field<SimpleForm> field)
{
field.SetPrompt(new PromptAttribute($"You chose a rating of {state.Rating}. What is your name?."));
return true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.