Skip to content

Instantly share code, notes, and snippets.

View aritchie's full-sized avatar

Allan Ritchie aritchie

View GitHub Profile
@aritchie
aritchie / MauiNet60.csproj
Created October 16, 2022 01:28
MAUI Single Project /w NET6.0 for unit tests
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!--net6.0 at the end makes vs4mac happy-->
<TargetFrameworks>net6.0-ios;net6.0-maccatalyst;net6.0-android;net6.0</TargetFrameworks>
<OutputType Condition="'$(TargetFramework)' != 'net6.0'">Exe</OutputType>
<RootNamespace>MyNamespace</RootNamespace>
<UseMaui>true</UseMaui>
@aritchie
aritchie / MyServiceLocator.cs
Last active January 26, 2024 21:45
MAUI Service Locator
using Microsoft.Extensions.Logging;
using System;
namespace YourNamespace;
// IMauiInitializeService will register immediately after MAUI has built its service container, so this class will be ready to go for all of your code
public class MyServiceLocator : Microsoft.Maui.Hosting.IMauiInitializeService
{
public static IServiceProvider Services { get; private set; }
async void Button_Clicked_3(System.Object sender, EventArgs args) {
var cts = new CancellationTokenSource();
try
{
// if any exception is thrown, the progress will be cleaned up automagically
using (var disp = UserDialogs.Instance.Loading(
"Long Load...",
// this will cancel the actual http call
() => cts.Cancel(),
"Cancel"))
@aritchie
aritchie / gist:41c9faba48de5ce25177b1cb11157623
Created July 11, 2016 02:26
Android Broadcast Receivers to RX Observables
public static class AndroidObservables
{
public static IObservable<Intent> WhenIntentReceived(string intentAction)
{
return Observable.Create<Intent>(ob =>
{
var filter = new IntentFilter();
filter.AddAction(intentAction);
var receiver = new ObservableBroadcastReceiver