I want to show textbox value incrementing / decrementing every second live on UI but not able to do it. I have bind textbox to property and through for loop increment/decrement and want to show each incremented or decremented value on textbox at interval of 1 seconds.It shows final updated value not every incremented / decremented value on textbox. Can anyone explain how to do it.
<TextBlock
x:Name ="CurrentAmplitude"
Margin="45,0,14.4,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding TotalCurrent,UpdateSourceTrigger=PropertyChanged}" />
For loop for increment/decrement in viewmodel
private void IncrementtoTargetAmplitude( double amp1, double amp2, double stepInterval, int ch)
{
for(double i = amp1; i < ch; i++)
{
Task.Delay(1000).ContinueWith(_ =>
{
TotalCurrent = TotalCurrent + stepInterval;
if ((amp2 - TotalCurrent) < stepInterval)
{
TotalCurrent = amp2;
RaisePropertyChanged(nameof(TotalCurrent));
}
});
RaisePropertyChanged(nameof(TotalCurrent));
}
}
private void DecrementtoTargetAmplitude(double amp1, double amp2, double stepInterval, int ch)
{
for (double i = amp1; i < ch; i++)
{
Task.Delay(1000).ContinueWith(_ =>
{
TotalCurrent = TotalCurrent - stepInterval;
});
if ((amp2-TotalCurrent) < stepInterval)
{
TotalCurrent = amp2;
}
RaisePropertyChanged(nameof(TotalCurrent));
}
I'm still getting final updated value from this function whereas I need every updated value from for loop. Is there a way to get those value ?