Embarrassing Inheritance Question
Situation:
- I have a third party control that inherits from System.Windows.Controls.ItemsCon开发者_运维技巧trol - I have an instance of this control called foo - foo has a ListCollectionView datasource with 5 items and no filter. - foo.Items.Count gives a result of 0 - (System.Windows.Controls.ItemsControl)(foo)).Items.Count of 5Where this happens:
- A XAML.cs file's constructorWhen this happens:
- In the xaml.cs file's constructor - After InitializeComponentUnverified claims:
- The owner of the third party control claims that it does not override Items in any way.Question:
- Why does foo.Items.Count return a different value than (System.Windows.Controls.ItemsControl)(foo)).Items.CountIt sounds like they have re-declared the property, i.e.
public new SomeContainer Items { get { ... } }
which is sometimes done to make the type of .Items
(etc) more specific; it does, however, break inheritance, unless care is taken to override the underlying implementation. Re their claim - if the above is correct then indeed they aren't overriding it in any way; they are re-declaring it (it depends on how literal you are being with "override", perhaps).
But: you can check this in any reflection tool or IL inspection tool, simply by looking at how the property is declared. Does it have a new
or newslot
, etc.
精彩评论