I have an application that I recently converted from a VS 2008.NET 3.5 project to a VS2010.NET 4 project. Some of the WPF dialogs in the project behave differently after the conversion. I would like to understand what causes this difference in behavior, so I can find and fix other areas that may now have problems.
As an example, I have an MVVM dialog that allows a user to enter a number. The number is stored internally as a double, and the user can only accept a dialogue if the text they are typing is a real double. Therefore, I have a text field associated with a row in the ViewModel, and an OK button that is enabled only if the row is a valid double. The corresponding Xaml is as follows:
<TextBox Text="{Binding ValueString, UpdateSourceTrigger=PropertyChanged}"/>
<Button IsEnabled="{Binding ValueIsValid}">OK</Button>
And the ViewModel looks like this:
class ViewModel : INotifyPropertyChanged
{
private double actualValue;
public string ValueString
{
get { return actualValue.ToString("G3"); }
set
{
double doubleValue;
if (double.TryParse(value, NumberStyles.Float, CultureInfo.CurrentCulture, out doubleValue))
{
actualValue = doubleValue;
ValueIsValid = true;
RaisePropertyChanged("ValueString");
}
else
{
ValueIsValid = false;
}
}
}
private bool valueIsValid = true;
public bool ValueIsValid
{
get { return valueIsValid; }
set
{
if (valueIsValid != value)
{
valueIsValid = value;
RaisePropertyChanged("ValueIsValid");
}
}
}
private void RaisePropertyChanged(string property)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
.NET 3.5, .NET 4, , . , "3.05555" .NET 3.5, . .NET 4 3.05, "5", "3.06", "3.07", 5. ValueString, ( , "G3" ), .NET 3.5.
.NET Framework 4 ( WPF 4), .
, VS2010, . BindingTest2008 VS 2008 .NET 3.5, BindingTest2010 VS 2010, .NET 4. , .NET 4 .
, .
.
. RaisePropertyChanged("ValueIsValid"); (, "3.1a" ) (, "3.1" ). , 3 . . "3.0545555" - , , , 3- .