小编mil*_*jos的帖子

使用IEnumerable/yield返回的向导导航

我是C#的新手,刚刚发现如何使用yield return来创建自定义的IEnumerable枚举.我正在尝试使用MVVM来创建向导,但是我无法弄清楚如何控制从一个页面到下一个页面的流量.在某些情况下,我可能希望显示某个步骤,而在其他情况下,它不适用.

无论如何,我的问题是我使用IEnumerable来返回每个后续页面,这非常好用,但我知道我可能正在做一些不正确/无意识的语言.子类只需要覆盖抽象步骤IEnumerable访问器:

public class HPLDTWizardViewModel : WizardBase
{
  protected override IEnumerable<WizardStep> Steps
  {
    get 
    {
      WizardStep currentStep;

      // 1.a start with assay selection
      currentStep = new AssaySelectionViewModel();
      yield return currentStep;
      // 1.b return the selected assay.
      SigaDataSet.Assay assay = ((AssaySelectionViewModel)currentStep).SelectedAssay;
      sigaDataSet = (SigaDataSet)assay.Table.DataSet;

      // 2.a get the number of plates 
      currentStep = new NumPlatesViewModel(sigaDataSet);
      yield return currentStep;
      ...
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

父类包含使用Steps属性的枚举器的导航逻辑:

public abstract class WizardBase : ViewModelBase
{
  private ICommand _moveNextCommand;
  private ICommand _cancelCommand;
  private IEnumerator<WizardStep> _currentStepEnumerator;

  #region …
Run Code Online (Sandbox Code Playgroud)

.net c# ienumerable

5
推荐指数
1
解决办法
375
查看次数

标签 统计

.net ×1

c# ×1

ienumerable ×1