ArcGISPortalViewer.ViewModel.MainViewModel.InitializeCommandAndMessages C# (CSharp) Method

InitializeCommandAndMessages() private method

private InitializeCommandAndMessages ( ) : void
return void
        private void InitializeCommandAndMessages()
        {
            // initialize ItemClick RelayCommand
            ItemClickCommand = new RelayCommand<object>((e) =>
            {
                // handle the type of EventArgs passed
                if (e == null) 
                    return;
                
                ArcGISPortalItem portalItem = null;                
                // the GridView sends ItemClickEventArgs
                if (e.GetType() == typeof(ItemClickEventArgs))
                    portalItem = ((ItemClickEventArgs)e).ClickedItem as ArcGISPortalItem;
                // our GalleryPreviewControl sends TileClickEventArgs
                else if (e.GetType() == typeof(TileClickEventArgs))
                    portalItem = ((TileClickEventArgs)e).ClickedTile as ArcGISPortalItem;

                if (portalItem != null)
                {
                    // 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;
                    // our GalleryPreviewControl sends TileClickEventArgs
                    else if (e.GetType() == typeof(TileClickEventArgs))
                        portalGroup = ((TileClickEventArgs)e).ClickedTile 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);
                    }
                }                
            });

            // initialize MoreClickCommand RelayCommand
            MoreClickCommand = new RelayCommand<object>((objectCollection) =>
            {
                if (objectCollection == null)
                    return;
            
                //Use the navigation service to navigate to the page showing the specific collection of portal items                
                _navigationService.Navigate(App.CollectionPageName, objectCollection);
            });

            // Register with  PopulateDataMessage 
            Messenger.Default.Register<PopulateDataMessage>(this, msg => { var _ = PopulateDataAsync(); });

            // Register with ChangedPortalServiceMessage 
            Messenger.Default.Register<ChangedPortalServiceMessage>(this, msg => { var _ = PopulateDataAsync(); });
        }
        #endregion