Adrian_Mills
New member
- Joined
- Jul 16, 2018
- Messages
- 1
- Programming Experience
- 10+
Hi i am struggling getting validation working here is the current scenario as dictated by the design brief
we have a core class
this is then used as a base class for our model Customer
in the view model we have the following
On the view for the customer we have the following
When validation is called and an error is present for this field (this is only field i am testing at the moment) we have the following
all this is working fine however when the GetErrors method is being called no property name is passed in and it is treated as entity validation
if i change the view model and the view to have the field listed on there as
Then it works however this isn't the desired way the company wants it to work as we will be duplicating fields.
Can any one explain how i can get the validation to work with out the field being on the view model?
Cheers
Adrian
we have a core class
abstract public class Customer_Core:Core, ICore { string organizationName; [Key] public long CustomerId { get; set; } public string OrganizationName { get { return organizationName; } set { organizationName = value; RaisePropertyChanged("OrganizationName"); } } }
this is then used as a base class for our model Customer
in the view model we have the following
public class VMRowBase<R>:IRow<R> where R : class, ICore { public bool IsNew { get; set; } public bool IsDeleted { get; set; } public R Entity { get; set ; } } public class VMBase<T> : BaseINPC, INotifyDataErrorInfo, IVMBase, IBaseViewModel<T> where T : class, ICore { IRow<T> _selectedRow; public IRow<T> SelectedRow { get { return _selectedRow; } set { _selectedRow = value; } } }
On the view for the customer we have the following
C#:
<TextBox x:Name="organizationNameTextBox" HorizontalAlignment="Left" Height="22" Text="{Binding SelectedRow.Entity.OrganizationName, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120" Margin="160,68,0,10"/>
When validation is called and an error is present for this field (this is only field i am testing at the moment) we have the following
internal void SetErrorDetails(ValidationResult Result) { propErrors = (Dictionary<string,List<string>>) Result.ErrorContent; OnPropertyErrorsChanged(propErrors.First().Key); string field = "SelectedRow.Entity." + propErrors.First().Key; OnPropertyErrorsChanged(field); }
all this is working fine however when the GetErrors method is being called no property name is passed in and it is treated as entity validation
if i change the view model and the view to have the field listed on there as
public string OrganizationName { get { return SelectedRow.Entity.OrganizationName; } set { SelectedRow.Entity.OrganizationName = value; RaisePropertyChanged("OrganizationName"); } }
Then it works however this isn't the desired way the company wants it to work as we will be duplicating fields.
Can any one explain how i can get the validation to work with out the field being on the view model?
Cheers
Adrian