To mention a personalized slider within a listview on Xamarin Forms, the following steps can be followed:
Here is an example of the code:
ViewModel:
public class SliderViewModel : INotifyPropertyChanged
{
private double value;
public double Value
{
get { return value; }
set
{
if (this.value != value)
{
this.value = value;
OnPropertyChanged("Value");
}
}
}
private double min = 0;
public double Min
{
get { return min; }
set
{
if (min != value)
{
min = value;
OnPropertyChanged("Min");
}
}
}
private double max = 100;
public double Max
{
get { return max; }
set
{
if (max != value)
{
max = value;
OnPropertyChanged("Max");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Custom ViewCell:
public class SliderViewCell : ViewCell
{
public SliderViewCell()
{
var slider = new Slider();
slider.SetBinding(Slider.ValueProperty, new Binding("Value"));
slider.SetBinding(Slider.MinimumProperty, new Binding("Min"));
slider.SetBinding(Slider.MaximumProperty, new Binding("Max"));
View = slider;
}
}
ListView:
var viewModel = new ObservableCollection<SliderViewModel>();
// Add some sliders to the viewModel collection
var listView = new ListView();
listView.ItemTemplate = new DataTemplate(typeof(SliderViewCell));
listView.ItemsSource = viewModel;
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-11-17 11:00:00 +0000
Seen: 16 times
Last updated: Aug 13 '21
How can one ensure that sub-classes have uniform method parameters in TypeScript?
How can the calculation of matrix determinant be performed using CUDA?
How can code repetition be prevented when using (box)plot functions?
When I attempt to generate a database, why does the azure-cosmos-emulator become unresponsive?
What steps can I take to prevent my webpage from slowing down when all parts of a div are displayed?