Skip to content

Instantly share code, notes, and snippets.

View markjulmar's full-sized avatar

Mark Smith markjulmar

View GitHub Profile
@markjulmar
markjulmar / UWPDeviceType.cs
Last active July 11, 2017 13:15
Detect UWP device type
public enum DeviceType
{
Phone,
Tablet,
Desktop,
IoT,
Xbox,
SurfaceHub,
HoloLens,
Other
@markjulmar
markjulmar / DisplayAlert
Created June 30, 2017 01:47
Show DisplayAlert from background thread.
private void Button_Clicked(object sender, EventArgs e)
{
Task.Run(() => OnShowAlert("Hello"));
}
private void OnShowAlert(string text)
{
string title = $"OnShowAlert tid={Environment.CurrentManagedThreadId}";
Device.BeginInvokeOnMainThread(
async () => await DisplayAlert(title, text, "OK"));
@markjulmar
markjulmar / WPFvForms.md
Created April 28, 2017 22:14
Comparing WPF and Forms

WPF vs. Xamarin.Forms

Xamarin.Forms takes a lot of design guidance from the XAML-based frameworks that came before it, particularly WPF. However, in other ways it deviates significantly which can be a sticky point for people attempting to migrate over. This document attempts to identify some of those issues and provide guidance where possible to bridge WPF knowledge to Xamarin.Forms.

App Lifecycle

The application lifecycle between WPF and Xamarin.Forms is similar. Both start in external (platform) code and launch the UI through a method call. The difference is that Xamarin.Forms always starts in a platform-specific assembly which then initializes and creates the UI for the app.

WPF

Main method > App > MainWindow
@markjulmar
markjulmar / move-repo.sh
Created August 29, 2016 15:45
Move Git repo
#!/bin/bash
# Sometimes you need to move your existing git repository
# to a new remote repository (/new remote origin).
# Here are a simple and quick steps that does exactly this.
#
# Let's assume we call "old repo" the repository you wish
# to move, and "new repo" the one you wish to move to.
#
### Step 1. Make sure you have a local copy of all "old repo"
### branches and tags.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using CastMyVote.Models;
using CastMyVote.Services;
using CastMyVote.ViewModels;
using Xamarin.Forms;
INFO [2016-04-12 11:10:50Z]: Starting Xamarin Studio 6.0 (build 4968)
INFO [2016-04-12 11:10:50Z]: Running on Mono 4.4.0 (mono-4.4.0-branch/a3fabf1) (64-bit)
INFO [2016-04-12 11:10:50Z]: Operating System: Mac OS X 10.11.4
Darwin Marks-MBP-2.local 15.4.0 Darwin Kernel Version 15.4.0
Fri Feb 26 22:08:05 PST 2016
root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
INFO [2016-04-12 11:10:50Z]: GTK: Using gtkrc from /Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/gtkrc.mac
2016-04-12 11:10:50.723 XamarinStudio[85523:25920012] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.
INFO [2016-04-12 11:10:50Z]: Using GTK+ 2.24.23
INFO [2016-04-12 11:10:51Z]: Add-in loaded: MonoDevelop.Core
using Xamarin.Forms;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
namespace GreatQuotes.Services
{
public class NavigationService
{
private static readonly Task TaskCompleted = Task.FromResult(0);
@markjulmar
markjulmar / Xamarin.Auth.diff
Created February 18, 2016 16:08
Fix double-processing of redirect_uri
--- a/src/Xamarin.Auth/OAuth2Authenticator.cs
+++ b/src/Xamarin.Auth/OAuth2Authenticator.cs
@@ -235,7 +235,7 @@ namespace Xamarin.Auth
@markjulmar
markjulmar / gist:d91a00e03fc255141058
Last active December 7, 2015 20:31
PickerCollection
using System;
using Xamarin.Forms;
using System.Collections;
using System.Diagnostics;
namespace MusicSearch.Infrastructure
{
public class PickerBindBehavior : Behavior<Picker>
{
Picker associatedPicker;
@markjulmar
markjulmar / gist:28ee50416bcd8fafa10f
Created October 17, 2015 22:35
MTouch Commandline
1> Tool /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch execution started with arguments: --cache /Users/mark/Library/Caches/Xamarin/mtbs/builds/ProtocolAssistDeviceiOS/eea55df6b5e29402e5ed20c6a48dc92b/obj/iPhone/Debug/build-iphone8.1-9.0.2/mtouch-cache --dev /Users/mark/Library/Caches/Xamarin/mtbs/builds/ProtocolAssistDeviceiOS/eea55df6b5e29402e5ed20c6a48dc92b/bin/iPhone/Debug/build-iphone8.1-9.0.2/ProtocolAssistDeviceiOS.app --executable ProtocolAssistDeviceiOS --debug --linksdkonly --sdkroot /Applications/Xcode.app/Contents/Developer --sdk 9.0 --targetver 9.0 --aot-options=-O=-float32 --abi=armv7 --symbollist /Users/mark/Library/Caches/Xamarin/mtbs/builds/ProtocolAssistDeviceiOS/eea55df6b5e29402e5ed20c6a48dc92b/obj/iPhone/Debug/build-iphone8.1-9.0.2/mtouch-symbols.list --dsym=no -v -v -v -r /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/mscorlib.dll -r /Users/mark/Library/Caches/Xamarin/mtbs/builds/ProtocolAssistDeviceiOS/eea55df6b5e29402e5ed20c6a48dc