Using this thread I implemented the slider reduction prevention logic on my MAUI application.
But I have a DragCompletedCommand
also in the Slider
and which will do some actions. Here when clicking the lower time on slider at that time also the DragCompletedCommand
was hitting and doing those actions. How can I disable that?
I tried like below: Added a bool
variable on viewmodel
and check it’s value before doing the actions.
public ICommand DragCompletedCommand => new Command(OnDragCompleted);
private void OnDragCompleted(object obj)
{
if (invokeDragCompleted)
{
//My actions
}
}
I am setting that bool
value from homepage.xaml.cs
page’s ValueChanged
event.
public void SliderValueChanged(object sender, ValueChangedEventArgs args)
{
try
{
Slider slider = (Slider)sender;
IsIncrease = args.NewValue > args.OldValue;
if (!IsIncrease)
{
hpvm.InputTransparent = true;
slider.Value = args.OldValue;
value = args.OldValue;
hpvm.invokeDragCompleted = false;
}
else
{
hpvm.InputTransparent = false;
slider.Value = args.NewValue;
value = args.NewValue;
hpvm.invokeDragCompleted = true;
}
}
catch (Exception ex)
{
Debug.WriteLine("Exception:>>" + ex);
}
}
But this event is always firing when the timer runs and hitting if and else block alternatively. So the bool
value is getting true from here and doing the actions on the Viewmodel
. Is there any way to set the bool
value to false when choosing a lower time?
My Slider code:
<Slider
x:Name="watchme_slider"
Grid.Column="1"
BackgroundColor="White"
MinimumTrackColor="#1c98d7"
MaximumTrackColor="#9a9a9a"
ThumbImageSource="ic_thumb_xx.png"
ValueChanged="SliderValueChanged"
InputTransparent="{Binding InputTransparent}"
Maximum="0.166666667"
Minimum="0"
DragCompletedCommand="{Binding DragCompletedCommand}"
HorizontalOptions="FillAndExpand"/>