Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So I have binded a List to a ListView where the List has items of type Album, where it has lots of properties including .Cover, which I is an image on disk. Well since I don't know what type of image is needed and how they have to be loaded (I only know using Image types for Winforms), I don't know the type yet.

Can someone show or post me a quick sample where it shows this sort of items being shown as images of a certain fixed size using their .Cover property?

In essence this would show:

  1. What type .Cover should be
  2. How to open images from disk for WPF (assuming it's different than Winforms image loading)
  3. How to show them on a ListView as images of a certain fixed size, scaling the images if necessary
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
337 views
Welcome To Ask or Share your Answers For Others

1 Answer

  1. ImageSource
  2. ImageSource myImageSource = new BitmapImage(new Uri(@"file://C:... something.jpg"));
  3. Specify a data template for the items in the ListView's ItemTemplate property:

    <Window.Resources>
        <DataTemplate x:Key="ItemTemplate">
            <StackPanel Orientation="Horizontal">
                <Image Width="10" Height="10" Stretch="Fill" Source="{Binding Cover}"/>
            <Label Content="{Binding Title}" />
            </StackPanel>
        </DataTemplate>
    </Window.Resources>
    
    <Grid x:Name="grid">
        <ListView ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding Albums}" />
    </Grid>
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...