Created
July 28, 2021 00:46
-
-
Save TBertuzzi/e2b641f114da21b86bc8caac415e4e4d to your computer and use it in GitHub Desktop.
EventAggregato
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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