Skip to content

Instantly share code, notes, and snippets.

@jassmith
Created July 17, 2015 03:53
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 jassmith/fc4cf31b45c73c91e68e to your computer and use it in GitHub Desktop.
Save jassmith/fc4cf31b45c73c91e68e to your computer and use it in GitHub Desktop.
public class SliderViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private double limitedValue = 10;
public double LimitedValue
{
get { return limitedValue; }
set
{
value = Math.Min (value, 50);
limitedValue = value;
Debug.WriteLine (limitedValue);
OnPropertyChanged ();
}
}
protected virtual void OnPropertyChanged ([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null)
handler (this, new PropertyChangedEventArgs (propertyName));
}
}
var contentPage = new ContentPage ();
contentPage.BindingContext = new SliderViewModel ();
var slider = new Slider {
Minimum = 0,
Maximum = 100,
VerticalOptions = LayoutOptions.CenterAndExpand
};
slider.SetBinding (Slider.ValueProperty, "LimitedValue");
contentPage.Content = slider;
MainPage = contentPage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment