获取组件向导的最后一步

时间:2012-03-30 20:10:05

标签: asp.net wizard icollection

C#向导控件具有在我们完成向导步骤时触发的事件 ActiveStepChanged 。当前步骤存储在名为 ActiveStepIndex 的属性中。我需要检索当前 ActiveStepIndex 之前的步骤。

我正在尝试这种方式但到目前为止没有结果:

ICollection s = wizTransferSheet.GetHistory(); 
IList steps = s as IList;
WizardStep lastStep = steps[steps.Count].Name;

1 个答案:

答案 0 :(得分:4)

根据向导的复杂程度,有时可能会非常棘手。您无法始终使用ActiveStepIndex。幸运的是,向导控件记录了所访问步骤的历史记录,您可以利用它来检索访问过的最后一步:

您可以使用此功能获取访问过的最后一步:

/// <summary>
/// Gets the last wizard step visited.
/// </summary>
/// <returns></returns>
private WizardStep GetLastStepVisited()
{
    //initialize a wizard step and default it to null
    WizardStep previousStep = null;

    //get the wizard navigation history and set the previous step to the first item
    var wizardHistoryList = (ArrayList)wzServiceOrder.GetHistory();
    if (wizardHistoryList.Count > 0)
        previousStep = (WizardStep)wizardHistoryList[0];

    //return the previous step
    return previousStep;
}

以下是我们其中一个向导的示例代码。该向导非常复杂,并且根据用户的操作有很多潜在的分支。由于这种分支,导航向导可能是一个挑战。我不知道这对你是否有用,但我认为值得包括它以防万一。

/// <summary>
/// Navigates the wizard to the appropriate step depending on certain conditions.
/// </summary>
/// <param name="currentStep">The active wizard step.</param>
private void NavigateToNextStep(WizardStepBase currentStep)
{
    //get the wizard navigation history and cast the collection as an array list 
    var wizardHistoryList = (ArrayList)wzServiceOrder.GetHistory();

    if (wizardHistoryList.Count > 0)
    {
        var previousStep = wizardHistoryList[0] as WizardStep;
        if (previousStep != null)
        {
            //determine which direction the wizard is moving so we can navigate to the correct step
            var stepForward = wzServiceOrder.WizardSteps.IndexOf(previousStep) < wzServiceOrder.WizardSteps.IndexOf(currentStep);

            if (currentStep == wsViewRecentWorkOrders)
            {
                //if there are no work orders for this site then skip the recent work orders step
                if (grdWorkOrders.Items.Count == 0)
                    wzServiceOrder.MoveTo(stepForward ? wsServiceDetail : wsSiteInformation);
            }
            else if (currentStep == wsExtensionDates)
            {
                //if no work order is selected then bypass the extension setup step
                if (grdWorkOrders.SelectedItems.Count == 0)
                    wzServiceOrder.MoveTo(stepForward ? wsServiceDetail : wsViewRecentWorkOrders);
            }
            else if (currentStep == wsSchedule)
            {
                //if a work order is selected then bypass the scheduling step
                if (grdWorkOrders.SelectedItems.Count > 0)
                    wzServiceOrder.MoveTo(stepForward ? wsServicePreview : wsServiceDetail);
            }
        }
    }
}