I have a form containing few TextBox elements and a progress bar. I want the progress bar to be updated when the TextBox's have some values assigned.
So when a value is set to a TextBox I increment ProgressPercent if the lenght is different from 0;
The problem is that I don't know what condition to use to check if any value was set before and to decrement if the TextBox will become blank again.
Bellow you have my code so far
ViewModel
private string firstName { get; set; }
private string progressPercent { get; set; }
public string FirstName
{
get
{
return this.firstName;
}
set
{
this.firstName = value;
this.RaisePropertyChanged(() => this.FirstName);
var vm1 = (new ViewModelLocator()).MainViewModel;
if (value.Length != 0) // Checks the string length
{
vm1.ProgressPercent += 3;
}
}
}
public int ProgressPercent
{
get
{
return this.progressPercent;
}
set
{
this.progressPercent = value;
this.RaisePropertyChanged(() => this.ProgressPercent);
}
}
XAML
<StackPanel>
<ProgressBar x:Name="progressBar1"
Value="{Binding ProgressPercent ,Mode=TwoWay}"
HorizontalAlignment="Left"
IsIndeterminate="False"
Maximum="100"
Width="800"/>
<TextBlock Text="First Name"/>
<TextBox x:Name="FirstNameTextBox" Text="{Binding FirstName, Mode=TwoWay}"/>
</StackPanel>
Any ideas how to do this?
You should not notify property changes if the property did not change. You always can know for sure when it becomes empty and the other way around.