2011-12-24 47 views
1

我是WPF中的新人。我想有效地顯示僱主名單。我不想使用標準DataGrid。它看起來像在asp.net中的Repeater。它應該包含兩行記錄,我可以自定義視圖,例如左側把圖像右側的一些信息放在一些類似的複選框中(而不是運行時)。你對我的建議是什麼?WPF數據列表

回答

0

您可以嘗試使用ListBox。 ItemsSource屬性綁定到你的收藏,以及自定義ItemTemplate:它

<ListBox x:Name="{EmployersList}"><!-- if you are using MVVM, bind the items here --> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <Grid> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="50"/> 
        <ColumnDefinition/> 
       </Grid.ColumnDefinitions> 
       <Image Grid.Column="0" Source="{Binding ImageUrl}"/> 
       <StackPanel Grid.Column="1" Orientation="Vertical"> 
        <TextBlock Text="{Binding Name}"/> 
        <TextBlock Text="{Binding Title}"/> 
        <CheckBox IsChecked="{Binding SomeProperty}"/> 
       </StackPanel> 
      </Grid> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

而且在後面的代碼:

employers = // get from database or web service 
EmployerList.ItemsSource = employers;