I seam to be having a little problem. Now, this may be me being stupid, but I can’t get an ObservableCollection to work if you pass it a generic type!
For example, consider the following code:
Public Class ItemBitCollection(Of TItem) Inherits ObservableCollection(Of ItemBit(Of TItem)) End Class Public Class ItemBit(Of TItem) Private m_item As TItem End Class
Now, if you create an instance of ItemBitCollection you will see an error on the IDE regardless of wither you use a custom object type or a String type to initialise it:
Why does this not work? What is ObservableCollection doing that maybe it should not? Time to get Reflector out…
After some looking at the source I am still none the wiser. Even if you dumb down your classes to the bare minimum you cant pass a generic type into an ObservableCollection.
This is a limitation if you ask me…
Annoying solution:
If you create a fixed class type:
Public Class ItemBitCollection(Of TItemBit) Inherits ObservableCollection(Of TItemBit) End Class Public MustInherit Class ItemBit(Of TItem) Private m_item As TItem End Class Public Class DefaultItemBit Inherits ItemBit(Of String) End Class
And then pass that class in it does work:
Dim o As New ItemBitCollection(Of DefaultItemBit)
Although this is a work around, it causes other problems in my code… Ahh well… worth a try…
What to read next
Creating a better TFS Sticky Buddy (Core)
Explains building a flexible WPF data model in VB.NET for visualising hierarchical relationships using generics, ObservableCollections, and …
Calling an object method in a data trigger
Explains how to call an object method in a WPF DataTrigger, the limitations with extension methods, and common errors when binding methods …
Detecting agile theatre with real delivery signals
Why Most Companies Operating Models Fail in Dynamic Markets
A concise comparison of Predictive and Adaptive Operating Models, explaining why traditional structures fail in dynamic markets and how …
Don’t Manage Dependencies, Remove Them
Explains why dependencies are a sign of poor system design and outlines steps to eliminate them by aligning teams, clarifying ownership, and …
The Estimation Trap: How Tracking Accuracy Undermines Trust, Flow, and Value in Software Delivery
Tracking estimation accuracy in software delivery leads to mistrust, fear, and distorted behaviours. Focus on customer value, flow, and …
Flow of Value vs Flow of Work – Misnomer or Useful Shorthand?
Compares “flow of value” and “flow of work” in Kanban, explaining why only validated outcomes count as value and stressing the need for …
Why Outsourcing DevOps Fails, and How Real Engineering Excellence Starts With Your Team
Avoid DevOps vendor lock-in, discover how true engineering excellence starts with partnership, not outsourcing. Ready to transform your …