Reputation: 4898
I'm creating a UserControl that's a specialized ListBox/View (type not relevant). Now I'm faced with the option to either keep the type as UserControl or Inherit the List control.
1) If I keep it as a UserControl I have a List control inside it and then I have to create a DP for ItemsSource and so on.
2) Let it inherit List control and thus it automatically exposes ItemsSource property.
Is either way acceptable or will it become some Code Horror. What is expected.
Is there maybe a option 3 I'm not aware off?
Upvotes: 3
Views: 617
Reputation: 70122
There is no single right answer I'm afraid. The relative merits are:
#1 Hosting a List
within a UserControl
PROs
ListView
, you can do this by simply not exposing it.CONs
ItemsSource
, ItemTemplate
properties etc ... You can however expose the ListView
as a property of your UserControl if you like.#2 Inheriting from ListView
PROs
ListView
instances.ListView
.CONs
ListView
.So, it really depends on what you want to achieve. Personally I would go for (1) if you want to significantly change the API, for example specialising the ListView for a very specific purpose. I would go for (2) if you are creating a highly generic extension.
Upvotes: 4