be_mi
be_mi

Reputation: 569

WPF ListView->GridView->StackPanel

I have a ListView that uses GridView to display some data. One of the fields contains a list with image paths. Therefore I defin a GridViewColumn and create a DataTemplate. Dis DataTemplate contains another ListView with the Images list as new DataContext. When I don't write anything in the inner StackPanel, I can see that a list of string (in the format AppName.ClassName) is displayed in left to right order. But whenever I try to display the strings as something else, eg

<Image Source="{Binding Name}" Height="32"/>

I get an System.Windows.Markup.XamlParseException . Even with data binding I get an exception. Eg

<Image Source="Images/Camera_32xLG.png" Height="32"/>

. Any hint, what I might do wrong?

        <GridViewColumn Header="Images">
          <GridViewColumn.CellTemplate>
            <DataTemplate>

              <ListView ItemsSource="{Binding Images}"  BorderThickness="0">
                <ListView.ItemsPanel>
                  <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal">

--> here is where I don't know what to do next     

                    </StackPanel>
                  </ItemsPanelTemplate>
                </ListView.ItemsPanel>
              </ListView>

            </DataTemplate>
          </GridViewColumn.CellTemplate>
        </GridViewColumn>

Upvotes: 1

Views: 3504

Answers (1)

Grx70
Grx70

Reputation: 10349

Since the StackPanel is a part of ItemsPanelTemplate, you should just define it's properties and not explicitly add any children. The way to specify appearance of each item is through the ListView.ItemTemplate property:

<ListView ItemsSource="{Binding Images}"  BorderThickness="0">
    <ListView.ItemsPanel>
       <ItemsPanelTemplate>
           <StackPanel Orientation="Horizontal" />
       </ItemsPanelTemplate>
    </ListView.ItemsPanel>
    <ListView.ItemTemplate>
        <DataTemplate>
            <Image Source="{Binding Name}" Height="32" />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Upvotes: 3

Related Questions