I was just watching a “how-to” type WPF video called How Do I: Use Attached Properties to Store Extra Data in WPF, and it was describing what to do when you want to associate two pieces of information with a single control. If you want to put one piece of information in, they say to use the Tag property.
<Grid>
<TextBox Tag="innerData">
</Grid>
Fair enough.
But then they say, “what happens if you want to store a second piece of data, say, an integer?” The solution, they say is to use an unused attached property.
<Grid>
<TextBox Tag="innerData" Canvas.Top="55">
</Grid>
They say because it’s in a Grid, no problem! I say “Bleh!” This strikes me as extremely nasty…and quite misleading to read. Is this common practice?
It’s quick and easy but it’s definitely preferable to define your own Attached Properties or custom control to handle these situations. This is the type of thing that’s okay for prototypes or quick one-off apps but shouldn’t be done if the code is going to have a real lifespan that will require maintenance down the road.