Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. WCF and WF
  4. Images in a listbox

Images in a listbox

Scheduled Pinned Locked Moved WCF and WF
wpfwcfperformancequestion
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Renovatio1510
    wrote on last edited by
    #1

    Hi. I want to display 1000 albums in a listbox. An album is presented using the title, the artist and the cover. As i've understood, the virtualization performed by a listbox (with the virtualizingstackpanel) permits to generate (present) only those items which are visible. In every moment i've only 6 items (albums) visible, so i suppose that the listbox, when my application starts, generates only 6 ListBoxItems, one for each album that is initially visible. I also suppose that, when the user scrolls, the ListBoxItems are re-used to present the albums that become visible. Anyway, when my application starts i see that the memory used is around 300 mbytes, while the memory usage whithout the listbox is 50 mbytes. So i think that the data-template used to present the albums is instantiated for all the 1000 albums and not only for the first 6 albums visible. It is possibile that i have to explicitly write code to load and onload images when the listboxitems where the images are shown becomes visible/invisible? My data-template is this one:

    <DataTemplate x:Key="DataTemplate">
    <StackPanel
    HorizontalAlignment="Left"
    Orientation="Horizontal">
    <Image
    HorizontalAlignment="Left"
    Name="image"
    Tag="image"
    Source="{Binding Path=Items[0].PreviewLocation}"
    Stretch="UniformToFill"
    Margin="0,0,5,0"/>
    <StackPanel
    HorizontalAlignment="Left"
    VerticalAlignment="Center"
    Width="85">
    <TextBlock
    Text="{Binding Path=Name}"
    Margin="0,0,0,1"
    TextTrimming="CharacterEllipsis"/>
    <TextBlock
    Name="Artist"
    Text="{Binding Path=Items[0].Artist}"
    FontWeight="Normal"
    FontSize="7"
    Foreground="#4b4b4

    M 1 Reply Last reply
    0
    • R Renovatio1510

      Hi. I want to display 1000 albums in a listbox. An album is presented using the title, the artist and the cover. As i've understood, the virtualization performed by a listbox (with the virtualizingstackpanel) permits to generate (present) only those items which are visible. In every moment i've only 6 items (albums) visible, so i suppose that the listbox, when my application starts, generates only 6 ListBoxItems, one for each album that is initially visible. I also suppose that, when the user scrolls, the ListBoxItems are re-used to present the albums that become visible. Anyway, when my application starts i see that the memory used is around 300 mbytes, while the memory usage whithout the listbox is 50 mbytes. So i think that the data-template used to present the albums is instantiated for all the 1000 albums and not only for the first 6 albums visible. It is possibile that i have to explicitly write code to load and onload images when the listboxitems where the images are shown becomes visible/invisible? My data-template is this one:

      <DataTemplate x:Key="DataTemplate">
      <StackPanel
      HorizontalAlignment="Left"
      Orientation="Horizontal">
      <Image
      HorizontalAlignment="Left"
      Name="image"
      Tag="image"
      Source="{Binding Path=Items[0].PreviewLocation}"
      Stretch="UniformToFill"
      Margin="0,0,5,0"/>
      <StackPanel
      HorizontalAlignment="Left"
      VerticalAlignment="Center"
      Width="85">
      <TextBlock
      Text="{Binding Path=Name}"
      Margin="0,0,0,1"
      TextTrimming="CharacterEllipsis"/>
      <TextBlock
      Name="Artist"
      Text="{Binding Path=Items[0].Artist}"
      FontWeight="Normal"
      FontSize="7"
      Foreground="#4b4b4

      M Offline
      M Offline
      MBursill
      wrote on last edited by
      #2

      You make mention of a VirtualizingStackPanel, and you show the DataTemplate, but not the ItemsPanel. Good chance you did, but have you tried:

      <ListBox.ItemsPanel>
      <ItemsPanelTemplate>
      <VirtualizingStackPanel/>
      </ItemsPanelTemplate>
      </ListBox.ItemsPanel>

      -Mike.

      R 1 Reply Last reply
      0
      • M MBursill

        You make mention of a VirtualizingStackPanel, and you show the DataTemplate, but not the ItemsPanel. Good chance you did, but have you tried:

        <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
        <VirtualizingStackPanel/>
        </ItemsPanelTemplate>
        </ListBox.ItemsPanel>

        -Mike.

        R Offline
        R Offline
        Renovatio1510
        wrote on last edited by
        #3

        Hi. Thank you for the answer! Yes i use a virtualizingstackpanel for the listbox. Anyway i think that the problem is that i didn't understand the real behaviour of the virtualization. I thought that when an item of my domain becomes invisible its container (listboxitem) is reused for another item. Instead, when an item is no more visible its container is disposed (only the UI element) and another one is created for the item that becomes visible. Anyway, i don't know why the image element in the data template is not garbage-collected when the listbox containing it is disposed (there are no more references to that image). Any helps? Thank you.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups