Created
November 18, 2020 23:04
-
-
Save jesulink2514/0214b4ca1cd83130c24d1fcce6499e79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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