help me please

After starting the application, the textbox does not give any error

Class

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; namespace WpfApplication2 { class Class1 : IDataErrorInfo { public string Name { get; set; } public string Error { get { return null; } } public string this[string columnName] { get { switch (columnName) { case "Name": if (string.IsNullOrEmpty(this.Name)) return "Name can't be empty."; break; } return string.Empty; } } } } 

XAML

 <Window x:Class="WpfApplication2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <TextBox HorizontalAlignment="Left" Height="23" Margin="201,114,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Text="{Binding Path=Name, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" /> </Grid> 

Application window

enter image description here

  • I have your example immediately shows the red frame. Did you forget to install the DataContext ? - VladD
  • @VladD Could you please clarify where exactly? - Nick Synev
  • @VladD Thank you! It was really necessary to indicate the context for the class in the Maine form, although in the example nothing was mentioned about it. - Nick Synev
  • Okay, then I will draw back, for future generations. - VladD

1 answer 1

The code is correct.

Investigation in the comments showed that the DataContext installation is missing.