Im a beginner in WPF programming, coming from .NET 2.0 C#.
Im trying to make a horizontal StackPanel
which should be filled with data from a table in a
Basically, you want to use a control capable of displaying an enumeration of objects. The control capable of this is the class ItemsControl
and all of its descendants (Selector
, ListBox
, ListView
, etc).
Bind the ItemsSource
property of this control to a list of objects you want, here a list of users you've fetched from the database. Set the ItemTemplate
of the control to a DataTemplate
that will be used to display each item in the list.
Sample code:
In a Resources
section (for example Window.Resources
):
In your Window
/Page
/UserControl
:
In your code behind:
UserList.ItemsSource = ... // here, an enumeration of your Users, fetched from your db