简体   繁体   中英

WPF: How to store data from a list of data templates

I have a ComboBox with "First Name" and "Last Name" options, a TextBox and "Add" button in a data template. I have OK and Cancel buttons in the modal dialog. "Add" button will add another row of the above datatemplate. Any item of this list can be edited before OK is pressed. How to get all the information added when OK is pressed?

Try to set the datatemplate as a listview's itemtemplate, bind the datatemplate to a viewModel. Set the ObservableCollection<viewModel> as the ItemsSource of the listview. Hope it helps :)

<ListView ItemTemplate="{StaticResource ResourceKey=DataTemplate}" ItemsSource="{Binding ItemList}" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM