Skip to content

Instantly share code, notes, and snippets.

View jfversluis's full-sized avatar

Gerald Versluis jfversluis

View GitHub Profile
@jfversluis
jfversluis / SwitchEffect.cs
Created January 16, 2017 17:17
Xamarin.Forms implementation of the SwitchEffect
using System;
using Xamarin.Forms;
namespace EffectsSample
{
public class SwitchEffect : RoutingEffect
{
public SwitchEffect () : base ("MyCompany.SwitchEffect")
{
}
@jfversluis
jfversluis / EffectsSamplePage.xaml
Created January 16, 2017 17:21
Sample app main page
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:EffectsSample" x:Class="EffectsSample.EffectsSamplePage">
<Switch VerticalOptions="Center" HorizontalOptions="Center">
<Switch.Effects>
<local:SwitchEffect />
</Switch.Effects>
</Switch>
</ContentPage>
@jfversluis
jfversluis / SwitchEffect.cs
Created January 16, 2017 18:02
Android platform specific SwitchEffect
using Android.Graphics;
using Android.Support.V7.Widget;
using EffectsSample.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ResolutionGroupName ("MyCompany")]
[assembly: ExportEffect (typeof (SwitchEffect), "SwitchEffect")]
namespace EffectsSample.Droid
{
@jfversluis
jfversluis / SwitchColorEffect.cs
Created January 16, 2017 19:42
Creating the attached properties
using System.Linq;
using Xamarin.Forms;
namespace EffectsSample
{
public static class SwitchColorEffect
{
public static readonly BindableProperty TrueColorProperty = BindableProperty.CreateAttached ("TrueColor", typeof (Color), typeof (SwitchColorEffect), Color.Transparent, propertyChanged: OnColorChanged);
private static void OnColorChanged (BindableObject bindable, object oldValue, object newValue)
@jfversluis
jfversluis / SwitchEffect.cs
Created January 16, 2017 19:49
iOS and Android implementation of SwitchEffect
// Android SwitchEffect.cs
public class SwitchEffect : PlatformEffect
{
Xamarin.Forms.Color _trueColor;
protected override void OnAttached ()
{
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBean) {
_trueColor = (Xamarin.Forms.Color)Element.GetValue (SwitchColorEffect.TrueColorProperty);
@jfversluis
jfversluis / EffectsSamplePage.xaml
Created January 16, 2017 19:52
Edited Xamarin.Forms page
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:EffectsSample" x:Class="EffectsSample.EffectsSamplePage">
<Switch VerticalOptions="Center" HorizontalOptions="Center" local:SwitchColorEffect.TrueColor="Yellow">
<!--<Switch.Effects>
<local:SwitchEffect />
</Switch.Effects>-->
</Switch>
</ContentPage>
@jfversluis
jfversluis / propertychangedfodysamplePage.xaml
Created February 7, 2017 08:22
INotifyPropertyChanged page
<?xml version="1.0" encoding="utf-8"?>
<ContentPage Title="INotifyPropertyChanged" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:propertychangedfodysample" x:Class="propertychangedfodysample.propertychangedfodysamplePage">
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="{Binding SampleText}" />
<Button Text="Change Text!" Clicked="Handle_Clicked" />
<Button Text="Go to Fody &gt;" Clicked="Handle_Clicked1" />
</StackLayout>
</ContentPage>
@jfversluis
jfversluis / propertychangedfodysamplePageModel.cs
Created February 7, 2017 08:25
PageModel for the INotifyPropertyChanged page
using System.ComponentModel;
namespace propertychangedfodysample
{
public class propertychangedfodysamplePageModel : INotifyPropertyChanged
{
private string _sampleText;
public string SampleText {
get { return _sampleText; }
<?xml version="1.0" encoding="utf-8"?>
<ContentPage Title="Fody" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:propertychangedfodysample" x:Class="propertychangedfodysample.propertychangedfodysampleWithFodyPage">
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<Label Text="{Binding SampleText}" />
<Button Text="Change Text!" Clicked="Handle_Clicked" />
</StackLayout>
</ContentPage>
@jfversluis
jfversluis / propertychangedfodysampleWithFodyPageModel.cs
Created February 7, 2017 08:50
PropertyChanged.Fody PageModel
using PropertyChanged;
namespace propertychangedfodysample
{
[ImplementPropertyChanged]
public class propertychangedfodysampleWithFodyPageModel
{
public string SampleText {
get;
set;