3

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

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

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

1 回答 1

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);
            }
        }
    }
}
于 2012-03-30T21:49:11.383 回答