Xaml - How To Make WPF Listview Display Images and Labels Dynamically - Stack Overflow [PDF]

  • 0 0 0
  • Gefällt Ihnen dieses papier und der download? Sie können Ihre eigene PDF-Datei in wenigen Minuten kostenlos online veröffentlichen! Anmelden
Datei wird geladen, bitte warten...
Zitiervorschau

25/04/2021

xaml - How to make WPF listview display Images and Labels dynamically - Stack Overflow

How to make WPF listview display Images and Labels dynamically Asked 5 years, 1 month ago

8

Active 6 months ago

Viewed 34k times

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:

8

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:







Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose

information in accordance with

Join Stack Overflow to learn, share knowledge, and build your career. Sign up

https://stackoverflow.com/questions/35786002/how-to-make-wpf-listview-display-images-and-labels-dynamically/35786257

1/5

25/04/2021

xaml - How to make WPF listview display Images and Labels dynamically - Stack Overflow



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:

wpf

xaml

listview

Your Share privacy Improve this question

edited Mar 8 '16 at 2:51

asked Mar 4 '16 at 0:46

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on yourLuke device and disclose Dinkler Follow information in accordance with our Cookie Policy. 581 2 14 31 Accept all cookies

Customize settings

Join Stack Overflow learn, share code knowledge, your up be a you post to your full source for this? and I ambuild wanting to career. do something similar and thisSign would 1 can great building block for me! – StealthRT Oct 26 '16 at 18:10 https://stackoverflow.com/questions/35786002/how-to-make-wpf-listview-display-images-and-labels-dynamically/35786257

2/5

25/04/2021

xaml - How to make WPF listview display Images and Labels dynamically - Stack Overflow

2 Answers

17

Active Oldest Votes

You're going to provide more info about the data itself i.e. what's it's format, how are you assigning it to the ItemsSource etc. For one thing you're not setting the ItemTemplate, so you might want to look at that first. For example if you have a class containing your movie data that looks like this: public class MovieData { private string _Title; public string Title { get { return this._Title; } set { this._Title = value; } } private BitmapImage _ImageData; public BitmapImage ImageData { get { return this._ImageData; } set { this._ImageData = value; } } }

Then you would display it with something like this:





UPDATE: Sorry, I thought it was obvious that you still needed to use a UniformGrid. Here is what your full XAML should look like:



Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose

information in accordance with >our Cookie Policy.