I assume that you're working with Prism Library from Brian Lagunas NuGet Gallery | Prism.Forms 7.2.0.1367 . In this library there is a behavior to convert Events fired by controls in views, to a Commands Properties in the behavior that can be databinded with Commands Properties in view-models.
See this example:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
xmlns:prism="http://prismlibrary.com"
x:Class="GeoNet.DrawStatus.Views.MainPage"
Title="{Binding Title}">
<Grid>
<esriUI:MapView x:Name="mapView"
Map="{Binding Map}">
<esriUI:MapView.Behaviors>
<prism:EventToCommandBehavior EventName="DrawStatusChanged"
EventArgsParameterPath="Status"
Command="{Binding DrawStatusChangedCommand}" />
</esriUI:MapView.Behaviors>
</esriUI:MapView>
<ActivityIndicator IsVisible="{Binding IsActivityVisible}"
IsRunning="{Binding IsActivityVisible}" />
</Grid>
</ContentPage>
EventToCommandBehavior was added to MapView control in the view. Each time MapView fires a "DrawStatusChanged" event, the behavior intercepts it, takes the Status property of DrawStatusChangedEventArgs parameter of the event and passes to ViewModel through CommandParameter property of the DrawStatusChangedCommand. There was a ActivityIndicatorControl addeded to the ContentPage, it's IsVisible and IsRunning properties have DataBindings to the IsActivityVisible property of the ViewModel.
The Constructor of the ViewModel class has the definition of an Action to handle calls to DrawStatusChangedCommand made from the EventToCommandBehavior added to the MapView control. Inside the Action, IsActivityVisible property of the viewmodel is changed depending on the value of the e parameter of type DrawStatus sent to it. This makes that the ActivityIndicator be visible when the DrawStatus is equal to InProgess, and invisible when is iqual to Completed. In order to made async load of the map inside the SetMap() method, the async clause must be added to it, although, as mentioned, this call is not necessary.
using System;
using System.Diagnostics;
using System.Windows.Input;
using Esri.ArcGISRuntime.Mapping;
using Prism.Commands;
using Prism.Navigation;
using ArcGisRuntimeUI = Esri.ArcGISRuntime.UI;
namespace GeoNet.DrawStatus.ViewModels
{
/// <summary>
///
/// </summary>
public class MainPageViewModel : ViewModelBase
{
private Map _map;
private bool _isActivityVisible;
/// <summary>
///
/// </summary>
public Map Map
{
get { return _map; }
set { SetProperty(ref _map, value); }
}
/// <summary>
///
/// </summary>
public bool IsActivityVisible
{
get { return _isActivityVisible; }
set { SetProperty(ref _isActivityVisible, value); }
}
/// <summary>
///
/// </summary>
public ICommand DrawStatusChangedCommand { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="navigationService"></param>
public MainPageViewModel(INavigationService navigationService)
: base(navigationService)
{
Title = "Main Page";
DrawStatusChangedCommand = new DelegateCommand<ArcGisRuntimeUI.DrawStatus?>((e) =>
{
if (e.HasValue)
{
IsActivityVisible = e.Value != ArcGisRuntimeUI.DrawStatus.Completed;
}
});
SetMap();
}
private void SetMap()
{
try
{
Map = new Map(BasemapType.StreetsNightVector, 4.5, -74.5, 10);
Map.Loaded += (o, e) =>
{
Debug.WriteLine("Map");
};
//await Map.LoadAsync();
}
catch(Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
}
Marcelo César Torres