Adrian
Adrian

Reputation: 20058

Can't show image and textblock inside a GridView

This is my simple code to do this:

 <Grid>
        <ListView>
            <ListView.View>
                <GridView>
                    <GridViewColumn>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Image Width="16" Height="16" Source="c:\myimage.jpg" />
                                    <TextBlock Text="Image Name"/>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>

But except the empty header, nothing shows up.
This is my first time using GridView. Am I missing something ?

Upvotes: 0

Views: 190

Answers (3)

Robert Levy
Robert Levy

Reputation: 29073

You probably don't want to use CellTemplate. Here is an intro-level example of ListView: http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1

Upvotes: 1

brunnerh
brunnerh

Reputation: 184296

Your ListView has no items, the CellTemplate is applied to each item in the list and if there are no items nothing will be shown. Did you perhaps mean to change the Header instead?

Upvotes: 1

paparazzo
paparazzo

Reputation: 45096

If you are not binding a source then it is not going to generate any rows. Show your XAML or code behind for binding a source.

Upvotes: 1

Related Questions