Creating a Close IResult, issue.

Topics: Actions & Coroutines
Apr 16, 2012 at 12:45 PM

This is my action on my Conductor:
 public IEnumerable NewWorkspace()
            yield return Close.Screen(ActiveItem);

            var projectWorkspace = _projectWorkspaceViewModel();

I use the following for my close result:

public class Close : IResult
        private readonly IScreen _screen;

        public Close(IScreen screen)
            _screen = screen;

        public static Close Screen(IScreen screen)
            return new Close(screen);

        public void Execute(ActionExecutionContext context)
            _screen.Deactivated += (sender, e) => Completed(this, new ResultCompletionEventArgs {WasCancelled = !e.WasClosed});

        public event EventHandler Completed = delegate { };


Now because the item is deactivated before the new item is set my iterator continues and sets the new item, the deactivation then completes and clears out this new item. Is there a better way to handle this? 

Apr 17, 2012 at 7:12 AM

I changed so that my ShowResult creates the VM asynchronously, this allows the deactivation to complete before my new item shows, well by sheer luck right, it would be nice if I could hook into a Closed event for a Screen after all the deactivation happens and it is removed from the conductor, for example now I am doing:

yield return Workspace.CloseCurrent();
yield return Workspace.Create();
yield return Show.Tab<StartViewModel>();

The Create will resolve the VM from the container in a Task and run it in the background, on complete the result will continue, because this second result does no block the final execution of the Deactivation it works fine, but I am still not 100% happy.