ArcGISPortalViewer.ViewModel.PortalCollectionViewModel.PortalCollectionViewModel C# (CSharp) Method

PortalCollectionViewModel() public method

public PortalCollectionViewModel ( INavigationService navigationService ) : System
navigationService INavigationService
return System
        public PortalCollectionViewModel(INavigationService navigationService)
        {
            Messenger.Default.Register<ChangeIncremetalCollectionMessage>(this, msg =>
            {
                try
                {
                    PortalItems = msg.ItemCollection;
                    CollectionTitle = PortalItems.Title;
                    CurrentCollection = PortalItems;
                }
                catch (Exception ex)
                {
                    var _ = App.ShowExceptionDialog(ex);
                }

            });

            Messenger.Default.Register<ChangePortalItemsCollectionMessage>(this, msg =>
            {
                try
                {
                    MyMapsItems = msg.ItemCollection;
                    CollectionTitle = msg.Title;
                    CurrentCollection = MyMapsItems;
                }
                catch (Exception ex)
                {
                    var _ = App.ShowExceptionDialog(ex);
                }

            });

            Messenger.Default.Register<ChangeFavoritesCollectionMessage>(this, msg =>
            {
                try
                {
                    CollectionTitle = msg.Title;
                    CurrentCollection = FavoritesService.CurrentFavoritesService.Favorites;
                }
                catch (Exception ex)
                {
                    var _ = App.ShowExceptionDialog(ex);
                }

            });

            Messenger.Default.Register<ChangePortalGroupsCollectionMessage>(this, msg =>
            {
                try
                {
                    PortalGroups = msg.ItemCollection;
                    CollectionTitle = "Groups";
                    CurrentCollection = PortalGroups;
                }
                catch (Exception ex)
                {
                    var _ = App.ShowExceptionDialog(ex);
                }

            });

            // initialize ItemClick RelayCommand
            ItemClickCommand = new RelayCommand<object>((e) =>
            {
                // handle the type of EventArgs passed
                if (e == null) return;

                ArcGISPortalItem portalItem = null;
                if (e.GetType() == typeof(ArcGISPortalItem))
                    portalItem = e as ArcGISPortalItem;
                // the GridView sends ItemClickEventArgs
                else if (e.GetType() == typeof(ItemClickEventArgs))
                    portalItem = ((ItemClickEventArgs)e).ClickedItem as ArcGISPortalItem;
                else if (e.GetType() == typeof(PointerRoutedEventArgs))
                    portalItem = ((PointerRoutedEventArgs)e).OriginalSource as ArcGISPortalItem;

                if (portalItem != null)
                {
                    //SelectedPortalItem = portalItem;

                    // send clicked item via a message to other ViewModels who
                    // are registered with ChangeItemSelectedMessage
                    Messenger.Default.Send<ChangeItemSelectedMessage>(new ChangeItemSelectedMessage() { Item = portalItem });

                    // use the navigation service to navigate to the page showing the item details
                    navigationService.Navigate(App.ItemPageName, portalItem);
                }
                else // check if it is a PortalGroup
                {
                    ArcGISPortalGroup portalGroup = null;
                    // the GridView sends ItemClickEventArgs
                    if (e.GetType() == typeof(ItemClickEventArgs))
                        portalGroup = ((ItemClickEventArgs)e).ClickedItem as ArcGISPortalGroup;

                    if (portalGroup != null)
                    {
                        // send clicked item via a message to other ViewModels who
                        // are registered with ChangeGroupSelectedMessage
                        Messenger.Default.Send<ChangeGroupSelectedMessage>(new ChangeGroupSelectedMessage() { Group = portalGroup });
                        //Use the navigation service to navigate to the page showing the item details
                        navigationService.Navigate(App.GroupPageName);
                    }
                }
            });
        }
PortalCollectionViewModel