0

I have a propery that is a hashset, and I would like to notify to the view when a property of the first element is changed.

I implemented the iterface for notify when the property changed, but I don't know how to notifiy to the view. I have this code in my view:

<DataGridTextColumn Header="Field01" Binding="{Binding Path=MyHashSet[0], Converter={StaticResource myValeuConverter}}"/>

The problem is that the HashShet does not have the way to access to elements, so I can't use myHashSet[0] or myHashSet.ElementAt(0) or something else.

If in my view model I use Linq, the hashset has the method First(), but in the view I don't know if it is possible to include Linq to have access to this methods.

So, is it possible to use in the converter the first element of my hashset?

Thanks.

Álvaro García
  • 18,114
  • 30
  • 102
  • 193

2 Answers2

4

A HashSet does not have an order (at least not that you can depend on). The concept of "First" does not apply.

From MSDN:

The HashSet class provides high-performance set operations. A set is a collection that contains no duplicate elements, and whose elements are in no particular order.

You'll want to choose some type of ordered collection type.

Maybe a SortedSet or an OrderedDictionary or maybe just a List?

Mark Peters
  • 17,205
  • 2
  • 21
  • 17
1

I'm not sure this will help you much or if it's the answer you're looking for:

Before adding the said "First" item to the HashSet, you could have a property in your ViewModel that references the item, and your xaml could have a binding to that property.

Ryan
  • 1,300
  • 12
  • 29