Skip to content

Instantly share code, notes, and snippets.

@jesulink2514
Created November 18, 2020 23:04
Show Gist options
  • Save jesulink2514/0214b4ca1cd83130c24d1fcce6499e79 to your computer and use it in GitHub Desktop.
Save jesulink2514/0214b4ca1cd83130c24d1fcce6499e79 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace FormsIcons.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class TechieSwitch : ITechiesSwitchController
{
public static BindableProperty IsOnProperty = BindableProperty.Create(nameof(IsOn), typeof(bool),
typeof(TechieSwitch), false, BindingMode.TwoWay, propertyChanged: OnPropertyChanged);
public TechieSwitch()
{
InitializeComponent();
}
public bool IsOn
{
get => (bool)GetValue(IsOnProperty);
set
{
SetValue(IsOnProperty, value);
}
}
private void ClickGestureRecognizer_OnClicked(object sender, EventArgs e)
{
IsOn = !IsOn;
}
private static void OnPropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
{
(bindable as ITechiesSwitchController).SetUITo((bool)newvalue);
}
async void ITechiesSwitchController.SetUITo(bool valueToShow)
{
var position = new Rectangle
{
Left = 20,
Top = 2,
Width = 16,
Height = 16
};
var uncheckedPosition = new Rectangle
{
Left = 2,
Top = 2,
Width = 16,
Height = 16
};
await Thumb.LayoutTo(valueToShow ? position : uncheckedPosition, 300, Easing.SinIn);
}
}
internal interface ITechiesSwitchController
{
void SetUITo(bool valueToShow);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment