Quantcast
Channel: Active questions tagged listview - Stack Overflow
Viewing all articles
Browse latest Browse all 790

How to make WPF listview display Images and Labels dynamically

$
0
0

I'm having quite a difficult time trying to create the UI for a WPF Window. I'm trying to display (dynamically) a bunch of Movie Posters with the name of the movie directly under the image. ItemsSource is assigned to a list of Images via foreach iteration. The Image files themselves may be different sizes, but as shown below I will be setting a uniform size.

Basically, my goal is for it to look something like this:

enter image description here

So far, My code only displays a window with one large horizontal row(?) with the image in the center and no label. Here's my XAML code:

<Window x:Name="TVWindow" x:Class="PACS_Pre_Alpha.TV"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    Title="TV" Height="746" Width="1000" ResizeMode="NoResize"><Grid x:Name="TVGrid"><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition /></Grid.RowDefinitions><ListView x:Name="TvBox" HorizontalAlignment="Left" Height="648" VerticalAlignment="Top" Width="994" Grid.Row="5" Grid.Column="5"><ItemsControl.ItemsPanel><ItemsPanelTemplate><UniformGrid Columns="5" /></ItemsPanelTemplate></ItemsControl.ItemsPanel><ListView.ItemTemplate><DataTemplate><StackPanel Orientation="Vertical" VerticalAlignment="Stretch"><Image Source="{Binding ImageData}" HorizontalAlignment="Center" VerticalAlignment="Top" /><TextBlock Text="{Binding Title}" HorizontalAlignment="Center" VerticalAlignment="Bottom" /></StackPanel></DataTemplate></ListView.ItemTemplate></ListView></Grid>

My movies are added with this C# code:

foreach (string tvf in ContentFiles){            string ContentTitle = System.IO.Path.GetFileNameWithoutExtension(tvf);            MovieData cnt = new MovieData();            cnt.ImageData = LoadImage(ActualImage);            cnt.Title = ContentTitle;            ContentDataList.Add(cnt);}        TvBox.ItemsSource = ContentDataList;

Edit: I have changed my XAML Markup as @MarkFeldman suggested, but now nothing appears.Edit: It currently looks like this:enter image description here


Viewing all articles
Browse latest Browse all 790

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>