Skip to content

Instantly share code, notes, and snippets.

View TBertuzzi's full-sized avatar
👨‍💻
Works on My Device 📱

Thiago Bertuzzi TBertuzzi

👨‍💻
Works on My Device 📱
View GitHub Profile
@TBertuzzi
TBertuzzi / setup.cs
Created July 28, 2021 01:00
EventAggregator
services.AddTransient<IMainViewModel, MainViewModel>();
services.AddTransient<ISomarViewModel, SomarViewModel>();
services.AddTransient<MainPage>();
services.AddTransient<SomarPage>();
//Importante ser singleton
services.AddSingleton<IEventAggregator, EventAggregator>();
services.AddSingleton<App>();
using System;
using System.Threading.Tasks;
using MvvmHelpers;
using XamarinFormsEventAggregator.Events;
namespace XamarinFormsEventAggregator.ViewModels
{
public class SomarViewModel : BaseViewModel
{
private readonly IEventAggregator _EventAggregator;
@TBertuzzi
TBertuzzi / MainViewModel.cs
Created July 28, 2021 00:46
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
@TBertuzzi
TBertuzzi / SomarMessage.cs
Created July 28, 2021 00:44
EventAggregator
using System;
namespace XamarinFormsEventAggregator.Events
{
public class SomarMessage
{
public string Texto { get; set; }
}
}
@TBertuzzi
TBertuzzi / SomarPage.xaml
Created July 28, 2021 00:41
EventAggregator
<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamarinFormsEventAggregator.SomarPage">
<ContentPage.Content>
<StackLayout>
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
<Label Text="EventAggregator" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
</Frame>
@TBertuzzi
TBertuzzi / MainPage.xaml
Created July 28, 2021 00:40
EventAggregator
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Padding="0,60,0,0"
x:Class="XamarinFormsEventAggregator.MainPage">
<StackLayout>
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
<Label Text="EventAggregator" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
</Frame>
@TBertuzzi
TBertuzzi / EventAggregator.cs
Created July 28, 2021 00:38
EventAggregator
private static EventAggregator instance;
public static EventAggregator Instance
{
get
{
if (instance == null)
{
instance = new EventAggregator();
}
return instance;
@TBertuzzi
TBertuzzi / EventAggregator.cs
Last active July 28, 2021 00:34
EventAggregator
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace XamarinFormsEventAggregator.Events
{
public class EventAggregator : IEventAggregator
{
@TBertuzzi
TBertuzzi / IEventAggregator.cs
Created July 28, 2021 00:31
EventAggregator
using System;
namespace XamarinFormsEventAggregator.Events
{
public interface IEventAggregator
{
// Envia Mensagem e aguarda para ser processado na UI thread antes de retornar
void SendMessage<T>(T message);
// Publica a mensagem para processamento posterior na UI thread , retornando imediatamente.
@TBertuzzi
TBertuzzi / AppDelegate.cs
Last active July 5, 2021 17:17
Segurança Xamarin
public partial class AppDelegate : UIApplicationDelegate
{
NSObject _screenshotNotification = null;
public override void OnActivated (UIApplication application)
{
// Inicia a verificação
if (_screenshotNotification == null)
{
_screenshotNotification = UIApplication.Notifications.ObserveUserDidTakeScreenshot((sender, args) =>