Skip to content

Instantly share code, notes, and snippets.

View haavamoa's full-sized avatar
📱
Mobile developer ❤️ Open Sourcerer

Håvard Moås haavamoa

📱
Mobile developer ❤️ Open Sourcerer
View GitHub Profile
@haavamoa
haavamoa / LogicalExpressionConverter.cs
Last active February 21, 2019 07:38
Awesome converter to use when you have a list of bools that you want to convert
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace MynameSpace
{
#################################################################################################
# Checkout master, pull from master, prune master to remove branches that are merged with master
#################################################################################################
function gitcleanmaster(){
git checkout master
git pull
git remote prune origin
git branch --merged | grep -v "\*" | xargs -rn 1 git branch -d
}
@haavamoa
haavamoa / designbindingcontext, xam
Created June 13, 2019 07:37
A design binding context Resharper Live Template. I use this for Xamarin to get intellisense when binding the binding context in code behind rather than in XAML.
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:dblend="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="dblend"
dblend:DataContext="{dblend:DesignInstance $CLASSNAME$}"
@haavamoa
haavamoa / gist:92d236a8bef810cb9c92d10ab28e78c9
Created June 13, 2019 07:38
A Resharper Design DataContext Live Template. I use this when I bind the datacontext in code behind.
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance $CLASSNAME$}"
/// <summary>
/// A rounded frame behaviour, this will set the corner radius to the correct values if the frame has set its `HeightRequest`
/// Android : Corner radius should be the same as the height
/// iOS : Corner radius should be 58.33% of the height
/// </summary>
internal class RoundedFrameBehaviour : Behavior<Frame>
{
protected override void OnAttachedTo(BindableObject bindable)
{
base.OnAttachedTo(bindable);
@haavamoa
haavamoa / BiometricsService.cs
Last active March 24, 2020 21:22
Android BiometricsService using BiometricPrompt
using System;
using System.Threading.Tasks;
using Android;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Hardware.Biometrics;
using Android.OS;
using Android.Support.V4.App;
using Android.Support.V4.Hardware.Fingerprint;
namespace Visit.Mobile.MarkupExtensions
{
/// <summary>
/// A string case extension that can be used in XAML with static values (like localized strings).
/// Using this is the same as using a string case converter for bindings.
/// </summary>
[ContentProperty(nameof(Input))]
public class StringCaseExtension : IMarkupExtension
{
public string Input { get; set; }
public class IsEmptyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(!(value is string stringValue)) return false;
return string.IsNullOrEmpty(stringValue);
}
public class IsEmptyConverter : IValueConverter, IMarkupExtension
{
public bool Inverted { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(!(value is string stringValue)) return false;
return Inverted ? !string.IsNullOrEmpty(stringValue) : string.IsNullOrEmpty(stringValue);
}
<Label Text="Is visible if MyText is empty"
IsVisible="{Binding MyText, Converter={converters:IsEmptyConverter}}" />