Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add user controls as listbox items

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

I want my listbox to have a copy of the user control as the list items, with different contents within each one.

How do I add user controls to a listbox?

Thanks for your help in advance!

like image 434
Rob McCabe Avatar asked Aug 31 '13 20:08

Rob McCabe


1 Answers

You can set ItemTemplate for the listbox with your usercontrol in it.

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

Thanks

like image 178
Nitin Avatar answered Nov 05 '22 10:11

Nitin