public SearchViewModel(INavigationService navigationService)
{
// initialize ItemClick RelayCommand
ItemClickCommand = new RelayCommand<object>((e) =>
{
// handle the type of EventArgs passed
ArcGISPortalItem portalItem = null;
if (e == null)
portalItem = null;
// the GridView sends ItemClickEventArgs
else if (e is ItemClickEventArgs)
portalItem = ((ItemClickEventArgs)e).ClickedItem as ArcGISPortalItem;
// 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);
});
// initialize SelectItemCommand RelayCommand
SelectItemCommand = new RelayCommand<object>((e) =>
{
// handle the type of EventArgs passed
ArcGISPortalItem portalItem = null;
if (e == null)
portalItem = null;
// the GridView sends SelectionChangedEventArgs
else if (e.GetType() == typeof(SelectionChangedEventArgs))
portalItem = ((SelectionChangedEventArgs)e).AddedItems.FirstOrDefault() as ArcGISPortalItem;
SelectedPortalItem = portalItem;
AppViewModel.CurrentAppViewModel.SelectedPortalItem = SelectedPortalItem;
});
// initialise SelectSortFieldCommand RelayCommand
SelectSortFieldCommand = new RelayCommand<object>((obj) =>
{
if (obj != null && obj is ComboBoxItem)
{
var content = ((ComboBoxItem)obj).Content;
if (content != null)
CurrentSortField = GetCurrentSortField(content.ToString());
SortResults(CurrentSortField);
}
});
// initialise SelectSearchDomainCommand RelayCommand
SelectSearchDomainCommand = new RelayCommand<object>((obj) =>
{
if (obj is ComboBoxItem)
{
var content = ((ComboBoxItem)obj).Content;
if (content == null) return;
var searchDomain = content.ToString();
if (string.IsNullOrEmpty(searchDomain)) return;
PortalService.CurrentPortalService.OrganizationResultsOnly = searchDomain == (string) Application.Current.Resources["SearchOrganization"];
if (SearchResults != null && SearchResults.IsEmpty)
SearchResults= null;
// refresh search results
UpdateResults();
}
});
}