Last active
November 6, 2015 10:13
-
-
Save AndriiTsok/a885b513c1e4c52e0d99 to your computer and use it in GitHub Desktop.
Implementation of bindable properties in Xamarin.Forms
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
///<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; | |
} | |
} |
Implement snippet
<_Group>C#
text/x-csharp
bprop
<_Description>Bindable Property
Unknown
PropertyName
TargetClass
PropertyType
DefaultValue
((obj)=> obj.$name$,$default$);
public $type$ $name$
{
get{return ($type$)GetValue($name$Property);}
set{ SetValue( $name$Property, value);}
}
]]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add comments and instruction by
// TODO: https://codemilltech.com/back-to-school-adding-a-custom-bindable-property-to-xamarin-forms/