Skip to content

Instantly share code, notes, and snippets.

View twolfprogrammer's full-sized avatar

Thomas Wolf twolfprogrammer

View GitHub Profile
@twolfprogrammer
twolfprogrammer / MenuPage.xaml.cs
Last active September 6, 2016 22:28
Creating a hamburger menu in Xamarin.Forms
public partial class MenuPage : ContentPage {
public MenuPage() {
Title = "Menu";
InitializeComponent();
// Add your UI code for the menu here or in your XAML file
}
}
@twolfprogrammer
twolfprogrammer / RequestManager.cs
Created August 24, 2016 04:43
Simple REST request code using ModernHttpClient
static HttpClient Client = new HttpClient(new NativeMessageHandler());
async Task<T> GetJsonAsync<T>(string url) {
T item = null;
var response = await Client.SendAsync(new HttpRequestMessage(HttpMethod.Get, new Uri(url)));
if (response.IsSuccessStatusCode) {
var json = await response.Content.ReadAsStringAsync();
item = JsonConvert.DeserializeObject<T>(json);
}
return item;
namespace MyCoolApp {
public class SomeClass {
public SomeClass{
DependencyService.Get<INativeCookieService>().ClearCookies();
}
}
}
using System;
using System.Net;
using Foundation;
using Xamarin.Forms;
[assembly: Dependency(typeof(MyCoolApp.iOS.NativeCookieService))]
namespace MyCoolApp.iOS {
public class NativeCookieService : INativeCookieService {
public void ClearCookies(){
foreach (NSHttpCookie cookie in NSHttpCookieStorage.SharedStorage.Cookies) {
using System.Net;
using Xamarin.Forms;
using Android.Webkit;
using System;
[assembly: Dependency(typeof(MyCoolApp.Droid.NativeCookieService))]
namespace MyCoolApp.Droid {
public class NativeCookieService : INativeCookieService {
public void ClearCookies(){
CookieManager.Instance.RemoveAllCookie();
using System;
using System.Net;
namespace MyCoolApp {
public interface INativeCookieService {
void ClearCookies();
}
}
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(Entry), typeof(MyCoolApp.iOS.CustomEntryRenderer))]
namespace MyCoolApp.iOS {
public class CustomEntryRenderer : EntryRenderer {
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) {
base.OnElementChanged(e);
if (this.Control != null) {
<?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="MyCoolApp.LoginPage">
<ContentPage.Content>
<StackLayout>
<Entry x:Name="usernameEntry" Placeholder="Username" />
<Entry x:Name="passwordEntry" Placeholder="Password" IsPassword="true" />
<Button x:Name="loginButton" Text="Login" Command="{Binding LoginCommand}" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
@twolfprogrammer
twolfprogrammer / NavigationService.cs
Last active November 17, 2016 21:13
MVVM Light & Xamarin.Forms: Navigation Service
// Based on: https://mallibone.com/post/xamarin.forms-navigation-with-mvvm-light
public class NavigationService : INavigationService {
private readonly Dictionary<string, Type> _pagesByKey = new Dictionary<string, Type>();
private NavigationPage _navigation;
public void Initialize(NavigationPage navigationPage){
_navigation = navigationPage;
}
public string CurrentPageKey {
@twolfprogrammer
twolfprogrammer / App.xaml.cs
Last active November 17, 2016 21:13
MVVM Light & Xamarin.Forms: App
public partial class App : Application {
private static Locator _locator;
public static Locator Locator {
get {
return _locator ?? (_locator = new Locator());
}
}
public App() {
var navigationPage = new NavigationPage(new HomePage());