开发者

How can i bind a list of my custom class(Ex :Student) objects to a list view in WPF

How can i bind a list of my custom class(Ex :Student) objects to a list view in WPF ? My XAML markup for :ListView is here.I want to show the users in the Listview like a html table

ListView Height="100" HorizontalAlignment="Left" Margin="27,98,0,0" Name="listView1" VerticalAlignment="Top" Width="320">
        <ListView.View>
            <GridView>
                <GridViewColumn Width="160" Header="Name"></GridViewColumn>开发者_开发百科
                <GridViewColumn Width="160" Header="Age"></GridViewColumn>

            </GridView>
        </ListView.View>
    </ListView>


A couple of things:

  1. Set the ListView.ItemsSource equal to the collection of Student objects.
  2. Set the DisplayMemberBinding property of the GridViewColumn. (An alternative is to set the CellTemplate property).

Applying these two to your sample XAML:

<ListView Height="100" HorizontalAlignment="Left" Margin="27,98,0,0" Name="listView1" VerticalAlignment="Top" Width="320" ItemsSource="{Binding StudentCollection}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="160" Header="Name" DisplayMemberBinding="{Binding Name}"></GridViewColumn>
                    <GridViewColumn Width="160" Header="Age" DisplayMemeberBinding="{Binding Age}"></GridViewColumn>

                </GridView>
            </ListView.View>
        </ListView>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜