Share via

The interface IDataErrorInfo does not work for the second window

Sarah 186 Reputation points
2022-03-11T23:07:27.927+00:00

I use the interface IDataErrorInfo to visualize errors in View. It works in MainWindow but not in AddContactView, although the code is the same.
The code is in the attached text fileApp-Code

Developer technologies | Windows Presentation Foundation
0 comments No comments

1 answer

Sort by: Most helpful
  1. Peter Fleischer (former MVP) 19,351 Reputation points
    2022-03-12T05:40:48.607+00:00

    Hi Sarah,
    in window "AddContactView" you use data object "Contact" (Type ContactModel).

        <Grid Margin="0,10,0,0">
            <StackPanel DataContext="{Binding Contact}">
    
                <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center" >
                    <Label Content="Firstname:"  FontWeight="SemiBold"/>
                    <TextBox Height="25" Width="290" MaxLength="91" Margin="0,0,5,0" Text="{Binding Firstname, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" ToolTip="{Binding ErrorCollection[Firstname]}" HorizontalContentAlignment="left" VerticalContentAlignment="Center"/>
    ...
    

    Type "ContactModel" doesn't implement Interface IDataErrorInfo

    public class ContactModel
    {
        public int Id { get; set; }
        public string Firstname { get; set; }
        public string Lastname { get; set; }
    }
    

    Please, use my early posted code with IDataErrorInfo in ContactModel.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.