Created a collection of items. Just in case, I stuffed a bunch of interfaces into it (then remove the unnecessary ones)

public class HighlightRulesCollection : DependencyObject, ICollection<HighlightRule>, INotifyCollectionChanged, ICollection, ICollectionViewFactory, IList, IList<HighlightRule>, IAddChild 

The bottom line is that I have the opportunity to define a collection in resources and then use it as StaticResources . But the trouble! Everything that I add to this collection in the xaml markup is not really added to it. That is, after initializing the collection, it is empty. What can be wrong?

UPD:

Here is a collection in resources

 <Window.Resources> <local:HighlightRulesCollection x:Key="hlRules"> <local:HighlightRule HightlightedText="qwe"> <local:HighlightRule.Highlights> <local:HighlightBackgroung Brush="Yellow"/> <local:HighlightForeground/> </local:HighlightRule.Highlights> </local:HighlightRule> </local:HighlightRulesCollection> </Window.Resources> 

Here on it (in the same window)

 <local:HighlightTextBlock TextWrapping="Wrap" Grid.Column="1" Text="{Binding Property}" HighlightRules="{StaticResource hlRules}"> 

But in the properties browser (at runtime)

enter image description here

As you can see, the collection is there, it is of the desired type, but it is empty.

For an example, here's a screen from a neighboring control (I directly added elements of the collection to it)

enter image description here

  • aren't random collections being created? that is, one in the code, and the other in xaml - Gardes
  • @ S.Kost, read the update. - iRumba
  • You have two options at once: ICollection<HighlightRule> and IList<HighlightRule> , try removing ICollection<HighlightRule> . Must earn - Gardes
  • @ S.Kost, did not help - iRumba
  • @iRumba: Can't it be such an accident that one of the controls from you removes items from the collection? You have a common collection. - VladD

0