WPF Databinding stackpanel

前端 未结 2 2097
野性不改
野性不改 2020-12-13 10:12

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

2条回答
  •  春和景丽
    2020-12-13 10:34

    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
    

提交回复
热议问题