1

Situation:
- I have a third party control that inherits from System.Windows.Controls.ItemsControl
- 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 5

Where this happens:
- A XAML.cs file's constructor

When this happens:
- In the xaml.cs file's constructor
- After InitializeComponent

Unverified 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.Count

JSWork
  • 1,015
  • 1
  • 12
  • 21
  • You're going to need to show some code. – Jonathan M Sep 27 '11 at 20:51
  • 4
    If you open up a disassembler (dotPeek is a good one), you'll be able to see if they are telling you the truth. Sounds like there's probably a `new` property called `Items` that hides the base class's property. – Joe Enos Sep 27 '11 at 20:52
  • 1
    Why unverified? Why not just open up ILSpy and check? – Kent Boogaart Sep 27 '11 at 20:53
  • What's the static type of foo? – Andreas Sep 27 '11 at 20:53
  • @DonAndre: Foo is a custom third party control that inherits form ItemsControl. I didn't include the name the new type out of respect to the vendor (I didn't see how it was relevant). That said, casting doesn't change the GetType results, if that's what you are asking. – JSWork Sep 27 '11 at 20:56
  • 1
    JonathanM, It's a third party control. @jsWork, probably third party control have created Items property with new modifier. Use reflection to check it – hungryMind Sep 27 '11 at 20:57
  • @JoeEnos: Thanks. I'll grab dotPeek and take a look under the hood to see what's really going on. – JSWork Sep 27 '11 at 20:57
  • You might want to take a look at this question. [Difference between shadowing and overriding in C#?](http://stackoverflow.com/questions/392721/difference-between-shadowing-and-overriding-in-c) – Conrad Frix Sep 27 '11 at 21:02

1 Answers1

7

It 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.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900