I just noticed there was a tag property for basically every control and item on the control, so I was thinking of assigning some references (to other objects) to them, which I would later retrieve and use when the user selects one of the items on the control.
Is there anything wrong with using tags like this? I don’t want to start abusing tags if they weren’t designed to be used that way.
For example, I have a list of files collected in a list of file entries. Each entry holds information such as the size of the file and the type of file.
A ListView that displays the list of filenames does not hold references to the actual entry which I need to retrieve data from.
So I would just assign a reference to the correct entry in the tag.
Is there some other way I could do this? Or should I just go with the tags and note down how I’m using tags in this application.
Yes, you can use the
Tagsproperty for that. It’s intended for keeping some bit of information for the control, without having to inherit it to add properties for the information.You should be somewhat careful what you store in the
Tagproperty, though. A simple object that just contains data is fine, but be careful about storing something that is disposable, as you would also need to prescribe to an event for the cleanup of the control, where you could dispose the data.