Loop through UserControl in WPF

Hey I was wondering if it is possible to skip a few WPF controls. So let's say I have a control that I want to render (with different data each time) 10-20 times depending on what it has.

The only alternative I found was to manually create 20 of these custom controls and hide the ones I didn't use.

Can they be encoded?

+1


a source to share


2 answers


You will probably need to clarify your question.

What do you mean by "loop through?"



When you say you want to render a control "10-20 times", do you mean that you have one control that you need to change 10-20 or 10-20 controls?

You may be interested in exploring DataTemplates and ItemsControls . You can bind an ItemsControl to an ObservableCollection containing different types of objects and then define different DataTemplates for each type of object contained in the collection. The ItemsControl will display the appropriate control for each object contained in the ObservableCollection.

+3


a source


I am assuming that you are already using data templates and you are asking how to loop through the objects created to represent your data from the DataTemplate. I'm right? You need to use VisualTreeHelper for this .



+4


a source







All Articles