简体   繁体   中英

C# WPF dynamically create a GUI element for each object in list

I have a list of objects (same class). Each of these objects has couple of properties. I would like to build a GUI that would show a "tile" for each of these objects and in this "tile" the property values of this object would be displayed. The image bellow illustrates the idea.

在此处输入图片说明

By pressing on the + tile it would be possible to add new object (would bring up the dialogue). The object tiles would wrap to the next line allowing X tiles per line.

What would be your suggestions to do this in a civilized manner to be able to automatically add/remove tiles as an object in the list is created/deleted? Maybe someone knows some examples?

Currently I'm quite blank on how to achieve this.

Consider using some sort of ItemsControl with a DataTemplate . I would review the follow tutorial on how to do that: http://wpftutorial.net/DataTemplates.html


As Matt Burland stated, you will need to put your objects into a ObservableCollection for them to appear "dynamically".

Please refer to this post -

WPF toolkit for tile listview

it outlines using a ItemsControl with wrap panel create a tile effect. Hope that helps.

1) Use a ListBox, bind ItemsSource property to your List. 2) Insert whatever kind of object you like in that list. 3) Create DataTemplate for each kind of object to display

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