Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have image and button column in ListView in WPF

I have to add two columns in a ListView. One column shows different Images and another column is used to show a Button.

It will be great help if anybody provide the any link or example source code. Thanks in advance.

like image 845
Ashish Ashu Avatar asked Dec 18 '09 04:12

Ashish Ashu


1 Answers

This would give you two columns one with a button one with an image. if i was doing it i would put a command on my item so i could bind my button to it.

  <ListView
     Name="myListView">
     <ListView.View>
        <GridView>
            <GridViewColumn>
              <GridViewColumn.CellTemplate>
                 <DataTemplate>
                    <Button
                       Content="Click Me"
                       Margin="0"
                       VerticalAlignment="Center"
                       Click="Button_Click" />
                 </DataTemplate>
              </GridViewColumn.CellTemplate>
           </GridViewColumn>

           <GridViewColumn>
              <GridViewColumn.CellTemplate>
                 <DataTemplate>
                    <Image
                       Source="{Binding ImageSource}" />
                 </DataTemplate>
              </GridViewColumn.CellTemplate>
           </GridViewColumn>
        </GridView>
     </ListView.View>
  </ListView>

You would need to have an items source containing items that have a property called ImageSource

like image 157
Aran Mulholland Avatar answered Sep 20 '22 18:09

Aran Mulholland