This project has moved. For the latest updates, please go here.

Urgent : Non Shared View & View Model from ViewNavigationEventArgs

Aug 23, 2012 at 10:53 PM

My Requirement is to create new View Model as Non-Shared View/ViewModel instead of Shared View /ViewModel from ViewNavigationEventArgs

Please find code snippet below.

Please help Urgent.

 

 public void HandleEvent(ViewNavigationArgs publishedEvent)
        {
            if (publishedEvent.Deactivate)
            {
                return;
            }
            IExportAsViewMetadata viewInfo = (from vi in ((ViewModelRouter) Router).Views
                                              where vi.Metadata.ExportedViewType.Equals(publishedEvent.ViewType)
                                              select vi.Metadata)
                .FirstOrDefault();

            if (viewInfo == null || !viewInfo.Category.Equals("Content")) return;
           
            if (publishedEvent.ViewType.Equals(_currentView)) return;

            if (!string.IsNullOrEmpty(_currentView))
            {
                EventAggregator.Publish(new ViewNavigationArgs(_currentView) {Deactivate = true});

                if (_goingBack)
                {
                    _goingBack = false;
                }
                else
                {
                    _history.Push(_currentView);
                }
            }

            BackCommand.RaiseCanExecuteChanged();

            _currentView = publishedEvent.ViewType;
        }

 

 

------

 

[Export(typeof (IModuleInitializer))]
    public class Bootstrapper : IModuleInitializer
    {
        [Import]
        public IFluentViewModelRouter Router { get; set; }

        #region Implementation of IModuleInitializer

        public void Initialize()
        {
           Router.RouteViewModelForView(Globals.MainPage, Globals.MainPage);
            Router.RouteViewModelForView(Globals.NavigationView, Globals.NavigationView);
            Constants.Router = Router;
            Initialized = true;
        }

        public bool Initialized { get; private set; }

        #endregion
    }