Skip to content

Instantly share code, notes, and snippets.

@TBertuzzi
Created July 28, 2021 00:46
Show Gist options
  • Save TBertuzzi/e2b641f114da21b86bc8caac415e4e4d to your computer and use it in GitHub Desktop.
Save TBertuzzi/e2b641f114da21b86bc8caac415e4e4d to your computer and use it in GitHub Desktop.
EventAggregato
using System;
using System.Threading.Tasks;
using MvvmHelpers;
using MvvmHelpers.Commands;
using Xamarin.Forms;
using XamarinFormsEventAggregator.Events;
namespace XamarinFormsEventAggregator.ViewModels
{
public class MainViewModel : BaseViewModel
{
private readonly IEventAggregator _EventAggregator;
public MvvmHelpers.Commands.Command SomarViewCommand { get; }
string _texto;
public string Texto
{
get
{
return _texto;
}
set
{
SetProperty(ref _texto, value);
}
}
public MainViewModel(IEventAggregator eventAggregator)
{
_texto = "Soma 0";
_EventAggregator = eventAggregator;
//Registra o Evento
EventAggregator.Instance.RegisterHandler<SomarMessage>(
SomarHandler);
SomarViewCommand = new MvvmHelpers.Commands.Command(async () => await SomarViewCommandExecute());
}
private void SomarHandler(
SomarMessage message)
{
Texto = message.Texto;
}
private async Task SomarViewCommandExecute()
{
await Xamarin.Forms.Application.Current.
MainPage.Navigation.PushAsync(new SomarPage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment