views:

27

answers:

2

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 ?

+2  A: 

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/

ArsenMkrt
A: 

Thanks,

I understand - but if you want to add some item from the code in runtime ?

How can you do it ?

Yanshof