I'm adding a slider into my xamarin app, but im using view models to capture values. How can I move the slider on the GUI and show the value incrementing up and down and then capture its value?
or is there a way I can include the "MySlider_ValueChanged" event and apply it to the view model page rather than the content page code behind file?
You have to find a BindableProperty which could be bound inside view model(
ICommand
) ,it should do the same work as the eventValueChanged
.For exmaple
We could handle
Tapped
event ofTapGestureRecognizer
in page code behind , we also could create newICommand
inside view model , and bind it withCommand
of TapGestureRecognizer .However, Slider does not have command whose function is detecting the value changed , there is only DragStartedCommand and DragCompletedCommand , so the only solution is to trigger your method inside the setter method of Value .
Xaml View ModelRefer https://stackoverflow.com/a/25141043/8187800.