Rearranging activation order

Topics: Framework Services
Jan 15, 2015 at 10:07 PM
During my override of OnActivate(), I need to call GetView() in order to focus an element. When I do this after I have previously activated my view, it's fine. But when I call this the first activation, it fails.

I was able to get it to work by swapping a few lines in ConductorBaseWithActiveItem<T>.ChangeActiveItem. The original is as follows:
        protected virtual void ChangeActiveItem(T newItem, bool closePrevious) {
            ScreenExtensions.TryDeactivate(activeItem, closePrevious);

            newItem = EnsureItem(newItem);

            if(IsActive)
                ScreenExtensions.TryActivate(newItem);

            activeItem = newItem;
            NotifyOfPropertyChange("ActiveItem");
            OnActivationProcessed(activeItem, true);
        }
and with my changes:
        protected virtual void ChangeActiveItem(T newItem, bool closePrevious) {
            ScreenExtensions.TryDeactivate(activeItem, closePrevious);

            newItem = EnsureItem(newItem);

            activeItem = newItem;
            NotifyOfPropertyChange("ActiveItem");

            if (IsActive)
                ScreenExtensions.TryActivate(newItem);

            OnActivationProcessed(activeItem, true);
        }
This seems to work. I haven't come across any problems doing this, but I'm curious if anyone knows better than I do what repercussions this change could have.

Thanks!
Jan 16, 2015 at 5:51 PM
I posted this on SO, sorry I didn't notice that was the official way now.

https://stackoverflow.com/questions/27990757/rearranging-parent-child-activation-order-in-caliburn-micro