Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6033005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:25:13+00:00 2026-05-23T05:25:13+00:00

I’m trying to have a TextBox’s content be validated using IDataErrorInfo. The source of

  • 0

I’m trying to have a TextBox’s content be validated using IDataErrorInfo. The source of the list below is a List and each item is display. When i put ValidatesOnDataErrors=True in the Binding for the Text on the TextBox, it’s not working as expected. How do I do this?

<ItemsControl ItemsSource="{Binding Trainings}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <StackPanel>
                    <TextBlock Text="{Binding MobileOperator}" />
                    <TextBlock Text="{Binding LastUpdate}"/>
                </StackPanel>
                <StackPanel>
                    <TextBlock Text="Number trained*" />                        
                    <!-- ValidatesOnDataErrors doesn't work here-->
                    <TextBox 
                        Text="{Binding NumberTrained, 
                                       ValidatesOnDataErrors=True}"/>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

Update: Posting a stripped down version of Model, ViewModel, View and CodeBehind

ViewModel and Model

public class MyViewModel : IDataErrorInfo, INotifyPropertyChanged
{
    public MyViewModel() 
    {
        Trainings = new List<MyModel>
        {
            new MyModel { NumberTrained = 5, MobileOperator = "MO 1", LastUpdate =         DateTime.Now },
            new MyModel { NumberTrained = 1, MobileOperator = "MO 2", LastUpdate = DateTime.Now },
        };

        OkButtonCommand = new ButtonCommand(OnClick);
    }

    private void OnClick()
    {
        PropertyChanged(this, new PropertyChangedEventArgs(""));
    }

    public event PropertyChangedEventHandler PropertyChanged;
    public ICommand OkButtonCommand { get; private set; }
    public List<MyModel> Trainings { get; private set; }
    public string Error { get { return null; } }

    public string this[string columnName]
    {
        get
        {
            string error = null;
            switch (columnName)
            {
                case "NumberTrained":
                    error = "error from IDataErrorInfo";
                    break;
            }
            return error;
        }
    }
}

public class MyModel
{
    public string MobileOperator { get; set; }
    public DateTime LastUpdate { get; set; }
    public int NumberTrained { get; set; }
}

public class ButtonCommand : ICommand
{
    private Action _handler;
    public event EventHandler CanExecuteChanged;

    public ButtonCommand(Action handler) { _handler = handler; }
    public bool CanExecute(object parameter) { return true; }
    public void Execute(object parameter) { _handler(); }
}

Code Behind

public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();

        DataContext = new MyViewModel();
    }
}

View

<Canvas x:Name="LayoutRoot" Background="White">
    <ItemsControl ItemsSource="{Binding Trainings}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <StackPanel HorizontalAlignment="Center">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                        <TextBlock Text="{Binding MobileOperator}" Margin="15,15,0,0" FontWeight="Bold"/>
                        <TextBlock Text="{Binding LastUpdate, StringFormat=' - Last Updated: \{0:M/d/yy\}'}" 
                                   Margin="5,15,15,0" Foreground="Gray"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                        <TextBlock Text="Number trained*" />
                        <TextBox Width="50" Height="20" 
                                 Text="{Binding NumberTrained, Mode=TwoWay, ValidatesOnExceptions=True, ValidatesOnDataErrors=True}"/>
                    </StackPanel>
                </StackPanel>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    <Button Content="ok" Width="100" Height="20" Canvas.Left="248" Canvas.Top="207" Command="{Binding OkButtonCommand}"/>
</Canvas>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:25:14+00:00Added an answer on May 23, 2026 at 5:25 am

    You need to implement IDataErrorInfo on your Model, not your ViewModel.

    As it is right now, your a validation check is throwing an error when you try and validate the property MyViewModel.NumberTrained, which doesn’t exist, so the validation error never gets called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.