Skip to content

Instantly share code, notes, and snippets.

@dkudelko
Created December 21, 2015 15:41
Show Gist options
  • Save dkudelko/f41c155991f235a67a1b to your computer and use it in GitHub Desktop.
Save dkudelko/f41c155991f235a67a1b to your computer and use it in GitHub Desktop.
BindableProperty XamarinForms
public static readonly BindableProperty FoobarProperty=BindableProperty.Create<YourClass, bool>( p => p.Foobar, false );
public bool Foobar
{
get
{
return (bool)GetValue(FoobarProperty);
}
set
{
SetValue(FoobarProperty, value);
}
}
protected override void OnPropertyChanged(string propertyName)
{
base.OnPropertyChanged(propertyName);
switch( propertyName )
{
case "Foobar":
UpdateFoobar();
break;
}
}
private void UpdateFoobar()
{
// Do whatever you need to do when the property
// has been set here. By the time this method is
// called Foobar will already hold the updated value
// so if you need to reference the old value you will
// need to store it in a class variable
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment