I’ve got this code to dynamically create checkboxes and hook them up to a shared OnTapped event handler:
private void CreateNewGroup(int currentItem, string groupName)
{
CheckBox ckbx = new CheckBox();
ckbx.Content = groupName;
ckbx.Tag = currentItem; // Don't know if this is needed
ckbx.Tapped += new TappedEventHandler(this.Checkbox_OnTapped);
stackPanelCheckBoxesParent.Children.Add(ckbx);
}
…as the comment shows, I don’t know if assigning a val to the Tag property is superfluous. The only reason I added it is because here: Dynamically (programatically) adding check boxes and checkedchanged events, a couple of people say to be sure to assing to the ID property of the dynamically created checkbox. Yet in Windows 8 C# apps there is no such property, apparently.
Definition of Control.Tag:
So unless you need to associate an object with your control you can omit it, will you be later accessing the
currentItem?