I know this question has been asked before. I'm not satisfied with answer which was given.
I'm looking for a compile-time solution. Is there a way to say hide the Items
and ItemSource
members without breaking the functionality of the class or is this not expected functionality? For example, could I create an ItemsControl<T>
via reflecting ItemsControl
and changing code or how could I go about achieving this?
To elaborate, I'm making an SlideShow control to display images in a slide show. It inherits from ItemsControl as it would have multiple children, but I would like to restrict it's children to Image objects only because I need access to these objects. I would like to enforce this restriction at compile time so I can safely access specific Image members without worrying what type the children are.
I figured it out. There is a control in the Windows Phone Toolkit that has the exact same behavior I am looking for. The TiltEffect dependency object enforces it's parent type at compile time. "Property IsTiltEnabled does not support values of type ..." I just have to do the same, but for the Children of my control.
What you need to do, more specifically is change the Items (through ItemsSource...) of the ItemsContorl to be a strongly typed collection, e.g. an ObservableCollection