虚拟化的ListView价值循环重复的模式 [英] ListView Virtualization value repeating in Recycling Mode
问题描述
我有一个支持虚拟化ListView控件一个奇怪的问题。我创建了一个非常小的试点应用重现该问题。当我输入,在列表视图东西几文本框,然后向下滚动时,键入的值在下面的文本框不变重复几页后。
I have a strange problem with virtualization enabled ListView control. I created a very small pilot app to reproduce the issue. When I type-in something for a few textboxes in the listview and then scrolling down, after a few pages the typed-in values are repeating in the untouched textboxes below.
下面是窗口的XAML:
Here is the XAML of the window:
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid Name="mainGrid">
<ListView ItemsSource="{Binding Path=DemoList}" >
<VirtualizingStackPanel.IsVirtualizing>
True
</VirtualizingStackPanel.IsVirtualizing>
<VirtualizingStackPanel.VirtualizationMode>
Recycling
</VirtualizingStackPanel.VirtualizationMode>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBox MinHeight="20" MinWidth="200" Margin="4"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Window>
而code-背后:
And the code-behind:
namespace WpfApplication3
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
demolist a = new demolist();
mainGrid.DataContext = a;
}
}
public class demolist
{
public demolist()
{
DemoList = new List<string>();
for (int i = 0; i <= 5000; i++)
{
DemoList.Add("sss");
}
}
public List<string> DemoList { get; set; }
}
}
和有关该问题的一个屏幕截图:
http://kepfeltoltes.hu/120228/Capture1_www.kepfeltoltes.hu_.png
And a screen capture about the issue: http://kepfeltoltes.hu/120228/Capture1_www.kepfeltoltes.hu_.png
是否有任何选项来解决这个问题?我想这是涉及到回收模式,但我觉得这不应该是正常的行为。
Is there any option to solve this issue? I guess it is related to the recycling mode, but I think this should not be the normal behaviour.
由于提前,
伊什特万
推荐答案
这当然一个奇怪的效果,但它似乎是由于回收模式加上其实你不是TextBox.Text属性绑定到任何东西。
That's certainly an odd effect, but it's seems to be due to the recycling mode plus the fact you're not binding the TextBox.Text property to anything.
更改code这样的(对不起,名字的变更),所有应该很好:
Change your code like this (sorry for change of names) and all should be well:
public class RecyclingListViewModel
{
public RecyclingListViewModel()
{
Items = new List<DataItem>();
for (int i = 0; i <= 5000; i++)
{
Items.Add(new DataItem{Id = i, Name = i.ToString(CultureInfo.InvariantCulture)});
}
}
public List<DataItem> Items { get; set; }
}
public class DataItem
{
public int Id { get; set; }
public string Name { get; set; }
}
<ListView ItemsSource="{Binding Path=Items}" >
<TextBox MinHeight="20" MinWidth="200" Margin="4" Text="{Binding Name}"/>
这篇关于虚拟化的ListView价值循环重复的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!