0

I need to create table that all ListViewItem of this table will be build hold 1. Image 2. Text 3. Button

How can i do it ?

1 Answer 1

3

In WPF you don't have to inherit ListViewItem to add your properties, you can create your class with your properties and bind it to ListView's or ListBox's ItemSource and create ItemTemplate to show item as you like.

public class MyItem
{
  public string MyImagePath{get; set;}
  public string MyText{get; set;}
}

<ListView x:Name="GroupsView" ItemsSource="{Binding MyItemsList}" >
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <Image  Source="{Binding Path=MyImagePath}" />
                <TextBlock Margin="2,0,2,0" Text="{Binding MyText}"/>
                <Button .../>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Here are some resources about that

1.http://huydinhpham.blogspot.com/2008/11/using-listvew-to-display-complex-data.html

2.http://www.codewrecks.com/blog/index.php/2008/11/08/wpf-and-wrapping-text-inside-elements-of-a-listview/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.