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 914157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:40:29+00:00 2026-05-15T17:40:29+00:00

Something is wrong with my binding. But I can’t find it I have a

  • 0

Something is wrong with my binding. But I can’t find it

I have a status type control (UserControl) that has an ItemsControl with binding that relies on a ViewModelBase object which provides list of BrokenRules, like so:

<ItemsControl ItemsSource="{Binding BrokenRules}" >
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <TextBlock>
                <Hyperlink Foreground="Red" >
                    <TextBlock Text="{Binding Description}" />
                </Hyperlink>
            </TextBlock>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

The binding works the way I want to, in the sense that any and all broken rules Descriptions are displayed. A rule is pretty much just a description and a delegate that is executed when the rule is told to validate itself.

Most rules have Descriptions that are known up front, before the rule is asked to validate itself. For example, “Name is not valued” is a fine description of what went wrong if the validation delegate !Name.IsNullOrEmptyAfterTrim() fails.

The problem comes with one particular rule, which checks for duplicate names. If the dup check fails, I want to be able to say what the duplicated value is, which is impossible to know up front. So the rule needs to update the Description when the validation delegate is executed.

When I unit test or leave a debug trace in the validation delegate, the broken rule description is updated. But when I run the app, the broken rule description is what is was before it was updated.

I am therefore guessing my binding is not correct. Can anyone suggest what the problem / fix is?

Cheers,
Berryl

UPDATE ====================

This is code from my ViewModelBase class:

private readonly List<RuleBase> _rules = new List<RuleBase>();

// inheritors add rules as part of construction
protected void _AddRule(RuleBase rule) { _rules.Add(rule); }

public ObservableCollection<RuleBase> BrokenRules { get { return _brokenRules; } }
protected ObservableCollection<RuleBase> _brokenRules;

public virtual IEnumerable<RuleBase> GetBrokenRules()         {
        return GetBrokenRules(string.Empty);
}

public virtual IEnumerable<RuleBase> GetBrokenRules(string property)        {
    property = property.CleanString();

     _brokenRules = new ObservableCollection<RuleBase>();
    foreach (var r in _rules)            {
        // Ensure we only validate this rule 
        if (r.PropertyName != property && property != string.Empty) continue;

        var isRuleBroken = !r.ValidateRule(this);

        if (isRuleBroken) _brokenRules.Add(r);

        return _brokenRules;
    }
  • 1 1 Answer
  • 1 View
  • 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-15T17:40:29+00:00Added an answer on May 15, 2026 at 5:40 pm

    You must ensure that the BrokenRules observable collection instance doesn’t change, your code on the View Model should look something like:

    public ObservableCollection<BrokenRule> BrokenRules
    {
      get;
      set;
    }
    
    private void ValidateRules()
    {
      // Validation code
      if (!rule.IsValid)
      {
        this.BrokenRules.Add(new BrokenRule { Description = "Duplicated name found" });
      }
    }
    

    If for example, you do something like this instead:

    this.BrokenRules = this.ValidateRules();
    

    You would be changing the collection which is bound to the ItemsControl without notifying it and changes won’t reflect on UI.

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

Sidebar

Related Questions

I'm sure I must be doing something wrong. But can't for the life of
I must be doing something wrong. I can't seem to execute my CustomValidator's ServerValidate
Just tried to execute a small Lua script, but unfortunately I'm doing something wrong.
K... I'm doing something obviously wrong. I have a simple page with a file
I have a list view that has a column databound to a list.Count see
So obviously I am doing something wrong, but I just cannot seem to get
Am I doing something wrong or is it not possible to specify a generic
There's something wrong with my code or I'm just not understanding this fully. I
Am I doing something wrong is this a known issue with the ASP.NET MVC
Are methods calls really so slow or is there something wrong in my computer?

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.