I'm writing a card game (think on Magic for example) where I have 8 cards on the table all the time. Each card has 4 textboxes (name, skill A, skill B, description) and 2 images (mana and photo). I want to be able to access programmatically to any field at any time, for example, skill A on card #5.
I can't use the control name because I'll be accessing to Card5_SkillA, which is very inefficient.
I've tried grouping the controls inside a Grid
, and setting the Tag
field both at runtime and compiletime to "Skill_A" and try to find it like this:
foreach (UIElement c in mygrid.Children)
{
if ( c is TextBox && ((TextBox) c).Tag.ToString() == "Skill_A")
System.Windows.Forms.MessageBox.Show("you found me");
}
But when executing that loop the Tag
field is always null.
I've searched others questions but TreeHelper
seems overkill and I can't search by row/column because I want to be able to redesign the card dessign in the future without modifying the code.
Any advice? Thanks =)