Skip to content

Instantly share code, notes, and snippets.

@AndriiTsok
Last active November 6, 2015 10:13
Show Gist options
  • Save AndriiTsok/a885b513c1e4c52e0d99 to your computer and use it in GitHub Desktop.
Save AndriiTsok/a885b513c1e4c52e0d99 to your computer and use it in GitHub Desktop.
Implementation of bindable properties in Xamarin.Forms
///<summary>
///Provides a property that we can bind view model properties to. Notice that the name of the property
///follows the pattern of the using the instance property name followed by the word Property.
//</summary>
public static BindableProperty LeftTitleProperty =
BindableProperty.Create<CustomHeaderBox, string>(ctrl => ctrl.LeftTitle,
defaultValue: string.Empty,
defaultBindingMode: BindingMode.TwoWay,
propertyChanging: (bindable, oldValue, newValue) => {
var ctrl = (CustomHeaderBox)bindable;
ctrl.LeftTitle = newValue;
});
//The property that handles getting and setting our label/property.
public string LeftTitle {
get { return (string)GetValue(LeftTitleProperty); }
set {
SetValue (LeftTitleProperty, value);
//here we update the left title label
LeftTitleLabel.Text = value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment