Posted 13 years ago
by Pat Maneely
-
Software Engineering Manager,
Cobham Aerospace
I'm trying to use IDataErrorValidation to indicate errors on my property grid.
When an validation error occurs, the border of the associated box on the grid is turned red, but the error message doens't appear.
Can you please show me the error of my ways.
Here's the XAML. The PropGrid is in a Wizard Page...
<wizard:WizardPage x:Name="msmFSPPage"
Caption="System Configuration Parameters"
Description="This page contains the Parameters necessry to configuration the System"
Title="System Configuration Parameters Page"
HelpButtonVisible="False">
<propgrid:PropertyGrid IsSummaryVisible="True" SelectedObject="{Binding Path=SystemData}">
<propgrid:PropertyGrid.DataFactory>
<propgrid:TypeDescriptorFactory />
</propgrid:PropertyGrid.DataFactory>
</propgrid:PropertyGrid>
</wizard:WizardPage>
...
There is a View Model in between that has a property to bind the XAML to the following class.
Here's the code that has the data validation
class SystemData : INotifyPropertyChanged, IDataErrorInfo
{
...
/// <summary>
/// Part Number
/// </summary>
public string PartNum
{
get { return partno_; }
set { partno_ = value; NotifyPropertyChanged("PartNum"); }
}
[Browsable(false)]
public string this[string propertyName]
{
get
{
switch (propertyName)
{
case "PartNum":
lastError_ = ValidatePartNum(partno_, 0);
break;
default:
lastError_ = null;
break;
}
return lastError_;
}
}
protected string ValidatePartNum(string partNumber, int index)
{
if (...)
return "Invalid Part Number";
return null;
}
...
}
When an validation error occurs, the border of the associated box on the grid is turned red, but the error message doens't appear.
Can you please show me the error of my ways.
Here's the XAML. The PropGrid is in a Wizard Page...
<wizard:WizardPage x:Name="msmFSPPage"
Caption="System Configuration Parameters"
Description="This page contains the Parameters necessry to configuration the System"
Title="System Configuration Parameters Page"
HelpButtonVisible="False">
<propgrid:PropertyGrid IsSummaryVisible="True" SelectedObject="{Binding Path=SystemData}">
<propgrid:PropertyGrid.DataFactory>
<propgrid:TypeDescriptorFactory />
</propgrid:PropertyGrid.DataFactory>
</propgrid:PropertyGrid>
</wizard:WizardPage>
...
There is a View Model in between that has a property to bind the XAML to the following class.
Here's the code that has the data validation
class SystemData : INotifyPropertyChanged, IDataErrorInfo
{
...
/// <summary>
/// Part Number
/// </summary>
public string PartNum
{
get { return partno_; }
set { partno_ = value; NotifyPropertyChanged("PartNum"); }
}
[Browsable(false)]
public string this[string propertyName]
{
get
{
switch (propertyName)
{
case "PartNum":
lastError_ = ValidatePartNum(partno_, 0);
break;
default:
lastError_ = null;
break;
}
return lastError_;
}
}
protected string ValidatePartNum(string partNumber, int index)
{
if (...)
return "Invalid Part Number";
return null;
}
...
}