3

C# Wizard コントロールには、ウィザードのステップを移動するときにトリガーされるイベント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;
}

これは、ウィザードの 1 つからのサンプル コードです。ウィザードは非常に複雑で、ユーザーの操作に基づいて分岐する可能性が多数あります。その分岐のため、ウィザードのナビゲートは難しい場合があります。これがあなたにとって役立つかどうかはわかりませんが、念のために含める価値があると思いました.

/// <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 に答える