I'm using Ironpython 2.7. Is it possible to dynamically generate elements of a wpf window based on data found at runtime? The program will call a database and load parameters, and I'd like to generate a TextBox (and ComboBox) for each parameter loaded (e.g. if 4 parameters are loaded, the window will show 4 TextBoxes with corresponding ComboBoxes).
Is this something I can do with a property decorator? Will I have to generate the xaml dynamically to do this? For example:
import wpf
from System import Windows.Window
parameters = loadfromdatabase(args)....
xaml_filename = "program.xaml"
textBox_list = ""
cnt = 0
for param in parameters:
textBox_list += '<TextBox x:Name={} HorizontalAlignment="Left" Height="21" Width = "52" Margin="60,{},0,0" VerticalAlignment="Top"/>\n'.format(param,60+26*cnt)
cnt += 1
xaml_string = "<Window \n<Grid>\n" + textBox_list + "</Grid>\n</Window>"
with open(xaml_filename, "w") as f:
f.write(xaml_string)
class MyWindow(Window):
def __init__(self):
wpf.LoadComponent(self, xaml_filename)
if __name__ == '__main__':
Application().Run(MyWindow())