Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WPF Validation

$
0
0

Hi I encountering an issue with WPF and Validation

We are using Entity Framework and have an abstract entity c_Core this core is used for a common fields across numerous clients. This is the base class for the entity c where the clients custom fields resides.

we have a row class which looks like this 

   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 ; }
    }

this forms the base class for all our rows and is used

       

    public class CRow : VMRowBase<C>
    {


       public CustomerRow()
        {
            // Initialise the entity or inserts will fail
            Entity = new C();
            IsNew = true;
        }
    }

This is then used as a selected_row in the view model

the view has a field 

                            

  <TextBox x:Name="OrganizationName"  HorizontalAlignment="Left" Height="22"  
                 Text="{Binding  SelectedRow.Entity.OrganizationName

                        , Mode=TwoWay
                        , UpdateSourceTrigger=PropertyChanged
                        , ValidatesOnNotifyDataErrors =True
                        , ValidatesOnExceptions=true}" 
                 VerticalAlignment="Center" 
                 Width="120" 
                 Margin="161,92,0,10"

            />

the errorsChanged event is raised like this 

ErrorsChanged.Invoke(this, new DataErrorsChangedEventArgs( FieldName));

when we try and do validation using INotifyDataErrorInfo the geterrors method is called the propertyname is always empty so the field doesn't change it's state and the validation goes to the entity level.

If i place the field on the view model and use that instead of SelectedRow.Entity.OrganizationName it works fine.

Is there a better way of handling this type of validation.

Cheers


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>