c# - Editing Multiple Instances of a User Control -
i semi new c# , have made multiple instances of user command such
stackpanel stkpnl = new stackpanel(); stkpnl = sp; //sp beingness static objref of stackpanel in mainwindow (int = 0; < 5; i++) { usercontrol usrctrl = new usercontrol(); usrctrl = new usercontrol1(); usercontrol1.tb.text = "text:"+i; //tb beingness static objref of textblock in user command usrctrl.name = "usrctrl" + i; stkpnl.children.add(usrctrl); }
what wanting able phone call each user command made independently , edit specific textblock.text. eg: edit usrctrl3's textblock without altering other 4 user controls created.
i found kinda hard explain myself. allow me know if need clarification , sick seek best explain.
you can access specific element in collection using index this:
stkpnl.children[3].tb.text = "some text"; // edit 4th user command (usrctrl3)
or can utilize linq search on name.
the method singleordefault()
expects @ 1 match. if no match found, returns null
.
var thirdusercontrol = stkpnl.children.singleordefault(x => x.name == "usrctrl3"); if (thirdusercontrol != null) thirdusercontrol.tb.text = "some text";
c# wpf user-controls instance multiple-instances
No comments:
Post a Comment