Skip to content

Instantly share code, notes, and snippets.

@mr5z
Last active September 29, 2020 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mr5z/e5dcb22bf70799698a9cadcc9c78abcf to your computer and use it in GitHub Desktop.
Save mr5z/e5dcb22bf70799698a9cadcc9c78abcf to your computer and use it in GitHub Desktop.
bla bla
public static BindableProperty <insert the object nameof(Property) here> + Property = CreateProperty<T>(nameof(<insert the object nameof(Property) here>));
public T <insert the object nameof(Property) here>
{
get => (T)GetValue(<insert the object nameof(Property) here> + Property);
set => SetValue(<insert the object nameof(Property) here> + Property, value);
}
// TODO put this under Utility folder
public static BindableProperty CreateProperty<T>(string propertyName, T defaultValue = default, BindingMode mode = BindingMode.TwoWay)
{
return BindableProperty.Create(propertyName, typeof(T), typeof(BindableObject), defaultValue, mode);
}
// Example use case
public static BindableProperty MiddleButtonCommandProperty = CreateProperty<ICommand>(nameof(MiddleButtonCommand));
public ICommand MiddleButtonCommand
{
get => (ICommand)GetValue(MiddleButtonCommandProperty);
set => SetValue(MiddleButtonCommandProperty, value);
}
@kesarling
Copy link

public static BindableProperty LabelHeight = BindableHelper.CreateProperty(LabelHeight);
Correct?

@mr5z
Copy link
Author

mr5z commented Sep 29, 2020

public static BindableProperty LabelHeight = BindableHelper.CreateProperty(LabelHeight);
Correct?

yes. I'll give another example.

@kesarling
Copy link

it can't find BindableHelper
Some missing reference?

@kesarling
Copy link

This is what I have currently used:

		public static BindableProperty LabelHeight = BindableProperty.Create("LabelHeight", typeof(double), typeof(double), DeviceDisplay.MainDisplayInfo.Height);
		public BindableObject LabelHeightObject
		{
			get => (BindableObject) GetValue(LabelHeight);
			set => SetValue(LabelHeight, value);
		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment