Created
December 21, 2015 15:41
-
-
Save dkudelko/f41c155991f235a67a1b to your computer and use it in GitHub Desktop.
BindableProperty XamarinForms
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
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