How to add user controls to a list of list items

I am using WPF.net 4.5 (C #) and I would like to create a ListBox that contains a series of user controls. (If the list is the wrong type of control, let me know.)

I want my list to have an instance of a user control in the form of list items with different contents in each of them.

How to add user controls to the list?

Thanks for your help in advance!

+4
source share
2 answers

You can set an ItemTemplate for a list with your user control in it.

<ListBox> <ListBox.ItemTemplate> <DataTemplate> <local:UserControl1/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> 

thanks

+7
source

I think you can create a DataTemplate that has the same user interface or style as this UserControl. maybe just copy the paste you can get the DataTemplate as you want, however

  <DataTemplate> <local:UserControl1/> </DataTemplate> 

This king seems very strange to me, I don’t know how it can work the way you want, so I also want to know the answers.

0
source

Source: https://habr.com/ru/post/1499961/


All Articles