xaml - In WPF, is it possible to bind values to controls in a loop? -



xaml - In WPF, is it possible to bind values to controls in a loop? -

i have series of textblock controls, this:

<textbox name="tb1"/> <textbox name="tb2"/> <textbox name="tb3"/> <textbox name="tb4"/>

and have list of values i'd bind text boxes, in list:

list<string> texts = new list<string>(); texts.add("test1"); texts.add("test2"); texts.add("test3"); texts.add("test4");

currently, have manually set values of textboxes, this:

tb1.text = texts[0]; tb2.text = texts[1]; tb3.text = texts[2]; tb4.text = texts[3];

is possible in loop somehow? perhaps alter xaml take in list or programatically textboxes? lot in advance.

<itemscontrol items="{binding myvalues}"> <itemscontrol.itemtemplate> <datatemplate> <textbox text="{binding}"></textbox> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol>

in code behind declare property:

public string myvalues { homecoming new[] { "foo", "bar" }; }

and in code behind constructor set command datacontext:

this.datacontext = this;

wpf xaml

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -