Hello Chris,
using variable to store the preceding dialog could work. The variable should be defined in the dialog D. Shortly before you switch to dialog D, the current dialog (A.B or C) initializes this variable with a value identifying the original dialog. When you want to return from the dialog D, just switch to the dialog which is identifying by the content of the variable. This approach requires some additional programming.
I would therefore recommend to try other approach. According to your description '... returning from screen D ...', the dialog D is subordinate to A, B or C. In such case, I would limit to perform the PresentDialog() operation. This will overlap the current dialog A, B or C by the new dialog D. When dismissing the dialog D (by DismissDialog()), the original dialog A, B, or C is restored automatically. For example, the implementation of dialog A, B or C could perform following code to present the dialog D in the same context (in the same owner) of the original dialog:
Owner.PresentDialog( dialog_D, null, null, null, null, null, null, null, null, false );
In dialog D perform following code to dismiss it and return to the original dialog:
Owner.DismissDialog( this, null, null, null, null, null, false );
Important: When overlapping multiple dialogs, the old dialog is still visible. The user will thus see the dialog A overlapped by D. If this is not desired, specify in the PresentDialog() explicitly the Hide transition to apply on the overlapped dialog:
Owner.PresentDialog( dialog_D, null, null, null, null, Effects::ShowHideCentered, null, null, null, false );
I hope it helps you further.
Best regards
Paul Banach