c# - 返回任务中的对话框
问题描述
我在任务功能中有特定的对话框。有没有办法在不退出瀑布步骤的情况下返回任务中的某个对话框。
谢谢
我试过 cs.ActiveDialog.State["stepIndex"] = (int)cs.ActiveDialog.State["stepIndex"] -1; 返回到上一个对话框状态,但它执行下一个瀑布对话框
解决方案
在这种情况下,最常见的方法是用自身替换当前对话框,为每个瀑布步骤添加逻辑,以确定它是否应该执行或直接进入下一步。例如,您应该在对话框选项中设置要执行的步骤索引,然后检查是否在执行每个步骤时设置了该值。
例如,这里的瀑布步骤的简化版本可能如下所示;
当您想返回上一步时,您可以使用;
return await sc.ReplaceDialogAsync(YourCurrentDialogID, new YourCurrentDialog(stepIndexToGoBackTo));
然后在每个瀑布步骤中,您可以检查您是否指定了要跳回的特定步骤,如果没有,它会按顺序执行每个步骤。
public async Task<DialogTurnResult> PromptUser(WaterfallStepContext sc, CancellationToken cancellationToken)
{
var stepToExecute = sc.Options as int?;
if(!stepToExecute.HasValue || (stepToExecute.HasValue && stepToExecute.Value == sc.Index)
{
// either we haven't set a specific step to run, so we will execute anyway
// or we have specified a step to run and the index matches, so we conditionally execute
}
// a step index has been passed into the options, but it doesn't match the current step
// so drop through until we hit the right step.
return await sc.NextAsync();
}
请原谅上面的代码,它可能不完全符合,但应该是正确的。我在手机上写这个:)
推荐阅读
- mysql - SELECT EXISTS (SELECT 1 FROM favoritelist WHERE id=:id) 是什么意思
- javascript - 无法读取文本输入的未定义属性拆分
- python - 在 Python (Mac & Linux) 中扩展内存映射文件
- progressive-web-apps - 使用 Workbox 缓存外部下载
- python - 我的 chromedriver 立即打开并崩溃
- haskell - Haskell - 尝试使用 Prelude.read 使输出类型 a 也适用于 String
- google-cloud-platform - 如何在谷歌云存储(Python)中获取 blob 的 URI
- java - 获取数组长度时出错抛出异常
- bash - 如何使用 .sh 脚本登录 Linux 中的程序?
- c# - C#:从 Net Core 中的 DbContext 继承,构造函数:没有为此 DbContext 配置数据库提供程序