Showing items as images in a WPF ListView

前端 未结 2 1732
灰色年华
灰色年华 2020-12-12 05:36

So I have binded a List to a ListView where the List has items of type Album, where it has lots of properties including <

相关标签:
2条回答
  • 2020-12-12 05:47

    In xaml you'd define a DataTemplate in your Listview's ItemTemplate that uses an Image, binding it's Source property to a path on your file sysem.

    In other words, Cover can be of type string, a file path. If you want to scale, a pretty simple way is a ViewBox, which scales all it contains. However, Image itself probably has options to do scaling.

    0 讨论(0)
  • 2020-12-12 06:05
    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>
      
    0 讨论(0)
提交回复
热议问题