WPF ListView/Items Control - Another problem
-
Hi there, I posted yesterday a problem that I've fixed, but now I ran into another one. This is not a conversion problem, more like a bug. Please do the following in Bea's project to reproduce. 1. Open 'DataSource.cs' 2. Make the 'public Album()' look like below
public Album()
{
this.PicturesLeft = new ObservableCollection();
this.PicturesRight = new ObservableCollection();this.PicturesLeft.Add(new Picture(new Uri("Images\\\\2moons\_2.gif", UriKind.Relative), "Saturn", "Saturn is the most distant of the five planets known to ancient stargazers.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\earglobe.gif", UriKind.Relative), "Earth", "Earth, our home planet, is the only planet in our solar system known to harbor life.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\jupglobe.gif", UriKind.Relative), "Jupiter", "With its numerous moons and several rings, the Jupiter system is a \\"mini-solar system.\\"")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\marglobe.gif", UriKind.Relative), "Mars", "The red planet Mars has inspired wild flights of imagination over the centuries.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\merglobe.gif", UriKind.Relative), "Mercury", "The small and rocky planet Mercury is the closest planet to the Sun.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\nepglobe.gif", UriKind.Relative), "Neptune", "Neptune was the first planet located through mathematical predictions.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\plutoch\_2.gif", UriKind.Relative), "Pluto", "Long considered to be the smallest, coldest, and most distant planet from the Sun.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\uraglobe.gif", UriKind.Relative), "Uranus", "Uranus gets its blue-green color from methane gas above the deeper cloud layers.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\venglobe.gif", UriKind.Relative), "Venus", "At first glance, if Earth had a twin, it would be Venus.")); int i; for (i = 0; i <= 3; i++) { this.PicturesRight.Add(new Picture(new Uri("Images\\\\2moons\_2.gif", UriKind.Relative), "Saturn", "Saturn is the most distant of the five planets known to ancient stargazers.")); this.PicturesRight.Add(new Picture(new Uri("Images\\\\earglobe.gif", Uri
-
Hi there, I posted yesterday a problem that I've fixed, but now I ran into another one. This is not a conversion problem, more like a bug. Please do the following in Bea's project to reproduce. 1. Open 'DataSource.cs' 2. Make the 'public Album()' look like below
public Album()
{
this.PicturesLeft = new ObservableCollection();
this.PicturesRight = new ObservableCollection();this.PicturesLeft.Add(new Picture(new Uri("Images\\\\2moons\_2.gif", UriKind.Relative), "Saturn", "Saturn is the most distant of the five planets known to ancient stargazers.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\earglobe.gif", UriKind.Relative), "Earth", "Earth, our home planet, is the only planet in our solar system known to harbor life.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\jupglobe.gif", UriKind.Relative), "Jupiter", "With its numerous moons and several rings, the Jupiter system is a \\"mini-solar system.\\"")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\marglobe.gif", UriKind.Relative), "Mars", "The red planet Mars has inspired wild flights of imagination over the centuries.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\merglobe.gif", UriKind.Relative), "Mercury", "The small and rocky planet Mercury is the closest planet to the Sun.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\nepglobe.gif", UriKind.Relative), "Neptune", "Neptune was the first planet located through mathematical predictions.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\plutoch\_2.gif", UriKind.Relative), "Pluto", "Long considered to be the smallest, coldest, and most distant planet from the Sun.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\uraglobe.gif", UriKind.Relative), "Uranus", "Uranus gets its blue-green color from methane gas above the deeper cloud layers.")); this.PicturesLeft.Add(new Picture(new Uri("Images\\\\venglobe.gif", UriKind.Relative), "Venus", "At first glance, if Earth had a twin, it would be Venus.")); int i; for (i = 0; i <= 3; i++) { this.PicturesRight.Add(new Picture(new Uri("Images\\\\2moons\_2.gif", UriKind.Relative), "Saturn", "Saturn is the most distant of the five planets known to ancient stargazers.")); this.PicturesRight.Add(new Picture(new Uri("Images\\\\earglobe.gif", Uri
Disable item virtualization by adding VirtualizingStackPanel.IsVirtualizing="False" to the ListViews XAML, although if your going too be dealing with 100s of items you might want to look for a different solution.
-
Disable item virtualization by adding VirtualizingStackPanel.IsVirtualizing="False" to the ListViews XAML, although if your going too be dealing with 100s of items you might want to look for a different solution.
That did the trick. I have to ask though, why would I need to look for a different solution than the ListView for item counts greater than 100? What is the problem?
-
That did the trick. I have to ask though, why would I need to look for a different solution than the ListView for item counts greater than 100? What is the problem?
That piece of code disables item virtualization which improves performance by only creating the items that are visible and regenerating them as you scroll. See MSDN. Heres an altered version of that method that worked with virtualization enabled. It uses a method which was added in .NET 3.5 but Im guessing your using that as otherwise the sample would have probably worked.
public static FrameworkElement GetItemContainer(ItemsControl itemsControl, Visual bottomMostVisual)
{
return itemsControl.ContainerFromElement(bottomMostVisual) as FrameworkElement;
}You can see the effects by trying with and without virtualization if you add more iterations to your loop which adds the pictures. At 200 there was a noticable pause when it was disabled.
modified on Saturday, January 31, 2009 5:18 PM
-
That piece of code disables item virtualization which improves performance by only creating the items that are visible and regenerating them as you scroll. See MSDN. Heres an altered version of that method that worked with virtualization enabled. It uses a method which was added in .NET 3.5 but Im guessing your using that as otherwise the sample would have probably worked.
public static FrameworkElement GetItemContainer(ItemsControl itemsControl, Visual bottomMostVisual)
{
return itemsControl.ContainerFromElement(bottomMostVisual) as FrameworkElement;
}You can see the effects by trying with and without virtualization if you add more iterations to your loop which adds the pictures. At 200 there was a noticable pause when it was disabled.
modified on Saturday, January 31, 2009 5:18 PM
That worked great, thanks for all your help, I really appreciate it. I'm learning! :laugh: