Skip to content

Instantly share code, notes, and snippets.

View programmation's full-sized avatar

David Dancy programmation

View GitHub Profile
// http://forums.xamarin.com/discussion/comment/144204/#Comment_144204
// Projects is an ObservableCollection
<ListView x:Name="projectListView"
ItemsSource="{Binding Projects}"
SelectedItem="{Binding SelectedProject, Mode=TwoWay}">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell x:Name="textCell"
Text="{Binding Name}"
@programmation
programmation / CustomApplication.cs
Created August 27, 2015 06:00
Android Application subclass with AltBeacon support
using System;
using AltBeaconOrg.BoundBeacon;
using AltBeaconOrg.BoundBeacon.Powersave;
using AltBeaconOrg.BoundBeacon.Startup;
using Android.App;
using Android.Runtime;
namespace CustomApp.Droid
{
[Application]
@programmation
programmation / CustomLabelRenderer.cs
Created September 1, 2015 13:18
Vertical centring UILabel subclass implementing Xamarin.Forms LabelRenderer
using System;
using System.ComponentModel;
using CoreGraphics;
using CustomRendererTest.Controls;
using CustomRendererTest.iOS.Renderers;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer (typeof(CustomLabel), typeof(CustomLabelRenderer))]
@programmation
programmation / wobble.cs
Created September 18, 2015 07:04
Xamarin Forms View extension (wobble)
public static class ViewExtensions
{
public static void Wobble (this View view, int wobbles = 4, Action completion = null)
{
Task.Run (() => {
Device.BeginInvokeOnMainThread (async () => {
uint duration = 50;
var count = 4;
await view.RelRotateTo (5.0, duration, Easing.Linear);
for (var shake = 1; shake < count - 1; shake++) {
@programmation
programmation / shake.cs
Created September 18, 2015 07:24
Xamarin Forms View extension (shake)
public static void Shake (this View view, int shakes = 4, Action completion = null)
{
Task.Run (() => {
Device.BeginInvokeOnMainThread (async () => {
uint duration = 50;
await view.TranslateTo (5.0, 0, duration, Easing.Linear);
for (var shake = 1; shake < shakes - 1; shake++) {
await view.TranslateTo (-10.0, 0, duration, Easing.Linear);
await view.TranslateTo (10.0, 0, duration, Easing.Linear);
}
@programmation
programmation / BeginInvokeOnMainThreadAsync.cs
Created September 23, 2015 23:01
Async BeginInvokeOnMainThread returning a result
// from https://forums.xamarin.com/discussion/comment/154636/#Comment_154636
public static Task<T> BeginInvokeOnMainThreadAsync<T>(Func<T> a)
{
var tcs = new TaskCompletionSource<T>();
Device.BeginInvokeOnMainThread(() =>
{
try
{
var result = a();
tcs.SetResult(result);
@programmation
programmation / AsyncMixin
Last active October 20, 2015 04:45
Async mixin utilities
using System;
using System.Threading.Tasks;
namespace MyApp
{
// Borrowed from @rid00z (http://www.michaelridland.com)
public static class AsyncMixin
{
public static void RunForget(this Task t)
{
@programmation
programmation / GetPropertyInPCL.cs
Created February 11, 2016 21:50
GetProperty equivalent code in PCL
// https://forums.xamarin.com/discussion/comment/180081/#Comment_180081
// Platform project
{
var type = item.GetType();
var prop = type.GetProperty(picker.DisplayMember);
picker.Items.Add(prop.GetValue(item).ToString());
}
// PCL
{
@programmation
programmation / ExemptEncryptionKey.xml
Created March 7, 2016 04:38
Apple iOS exempt encryption key for use in info.plist
<key>ITSAppUsesNonExemptEncryption</key><false/>
private int GetNavBarHeight()
{
int resourceId = Resources.GetIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0)
{
return Resources.GetDimensionPixelSize(resourceId);
}
return 0;
}