Something is wrong with my binding. But I can not find it
I have a state type control (UserControl) that has a binding-related ItemsControl that relies on a ViewModelBase that provides a BrokenRules list, for example:
<ItemsControl ItemsSource="{Binding BrokenRules}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock>
<Hyperlink Foreground="Red" >
<TextBlock Text="{Binding Description}" />
</Hyperlink>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Binding works the way I want, in the sense that all and all broken rules are displayed. A rule is pretty much just a description and a delegate that runs when the rule is told to test itself.
Most of the rules have descriptions that are known ahead, before the rule is asked to confirm itself. For example, “Name is not rated” is a great description of what went wrong if the delegate is a validator! Name.IsNullOrEmptyAfterTrim () fails.
, . , , , . , .
unit test , . , - , .
, . - , /?
Cheers,
Berryl
=====================
ViewModelBase:
private readonly List<RuleBase> _rules = new List<RuleBase>();
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) {
if (r.PropertyName != property && property != string.Empty) continue;
var isRuleBroken = !r.ValidateRule(this);
if (isRuleBroken) _brokenRules.Add(r);
return _brokenRules;
}