Mahapps.metro: IDataErrorInfo not activating on TextBox

Created on 10 Sep 2016  路  6Comments  路  Source: MahApps/MahApps.Metro

I am not experianced wiht xaml and i tried mutch things to solve this
simply what i wanted is to implement IDataErrorInfo on textbox
im using this code:

  public partial class ExampleWindow: MetroWindow , IDataErrorInfo
    {
        public ExampleWindow()
        {
            InitializeComponent();
        }

        public string this[string columnName] { get { return "Empty Number"; } } //always to be an error

        public string Error { get { return string.Empty; } }   
    }
<Grid>
        <TextBox Height="20" Width="200" Controls:TextBoxHelper.Watermark="Enter Text" 
         Text="{Binding MyText, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}" />
</Grid>

and what i assume is that my Binding Name isnt good (MyText)

I know this question was here alot times before so im feeling sorry that i couldnt find answer by myself and bother you guys here :(

All 6 comments

Someting similar

<Controls:MetroWindow x:Name="Window" .....>
  <Grid>
        <TextBox Height="20" Width="200" Controls:TextBoxHelper.Watermark="Enter Text" 
         Text="{Binding ElementName=Window, Path=MyText, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}" />
  </Grid>
</Controls:MetroWindow>

``` c#
public partial class ExampleWindow: MetroWindow , IDataErrorInfo, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}

public ExampleWindow()
 {
     InitializeComponent();
 }

private string _MyText;

public string MyText
{
get { return _MyText; }
set
{
_MyText= value;
OnPropertyChanged("MyText");
}
}

public string this [string columnName]
{
get
{
string result = string.Empty;
if (columnName == "MyText")
{
if (string.IsNullOrWhitespace(MyText))
result = "MyText can not be empty";
}
return result;
}
}
public string Error { get { return string.Empty; } }
}
```

Still not working
image
not shure why :(

show code

image

image

i don't see declared name x:Name="Window" in MetroWindow

Wow Thanks :D did not thaught that can be the problem...
image

Thanks again :D

Issue can be closed now its solved :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

punker76 picture punker76  路  4Comments

Zebody picture Zebody  路  4Comments

bardospeter picture bardospeter  路  3Comments

AzureZeng picture AzureZeng  路  3Comments

Nova669 picture Nova669  路  3Comments