PropertyChanged 및 CollectionChanged에 대한 호출 수를 제한해야합니다.
업데이트 재산권과 새로운 값을 확인 == 과거와는 클래스 일치하지 않으면 그렇게 NotifyPropertyChanged
를 호출하지 않으면 그 두 UI 통지와 같이 다음 삽입을 제거하지 않습니다.
새 항목을 지정하기 만하면됩니다. items [4] = newitem.
가상화를 사용하고 있습니까?
항목이 표시되지 않으면 UI가 새로 고침되지 않는다고 생각합니다.
아래를 참조하십시오. 항목이나 항목을 업데이트하는 것 외에 다른 UI가 깜박 거리지 않습니다. 나는 당신이 PropertyChanged를 제대로 활용하지 못하고 있다고 생각합니다.
<Window x:Class="ListViewUpdate.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DataContext="{Binding RelativeSource={RelativeSource self}}"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Button Content="Add10000" Click="Button_Click"/>
<Button Content="UpdateFirst" Click="Button_Click_1"/>
<Button Content="UpdateLast" Click="Button_Click_2"/>
<Button Content="ReplaceFirst" Click="Button_Click_3" />
<Button Content="UpdateAll" Click="Button_Click_4"/>
</StackPanel>
<ListView Grid.Row="1" ItemsSource="{Binding Path=Persons}" DisplayMemberPath="Name" />
</Grid>
</Window>
namespace ListViewUpdate
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private ObservableCollection<Person> persons = new ObservableCollection<Person>();
public MainWindow()
{
InitializeComponent();
}
public ObservableCollection<Person> Persons { get { return persons; } }
private void Button_Click(object sender, RoutedEventArgs e)
{
for (UInt16 i = 0; i < 10000; i++)
{
Persons.Add(new Person(Guid.NewGuid().ToString()));
}
System.Diagnostics.Debug.WriteLine("");
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (Persons.Count == 0) return;
for (UInt16 i = 0; i < UInt16.MaxValue; i++)
{
Persons[0].Name = Guid.NewGuid().ToString();
}
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
if (Persons.Count == 0) return;
int last = Persons.Count - 1;
for (UInt16 i = 0; i < UInt16.MaxValue; i++)
{
Persons[last].Name = Guid.NewGuid().ToString();
}
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
if (Persons.Count == 0) return;
for (UInt16 i = 0; i < UInt16.MaxValue; i++)
{
Persons[0] = new Person(Guid.NewGuid().ToString());
}
}
private void Button_Click_4(object sender, RoutedEventArgs e)
{
foreach (Person p in Persons) p.Name = Guid.NewGuid().ToString();
}
}
public class Person: INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
private string name;
public string Name
{
get { return name; }
set
{
if (name == value) return;
name = value;
NotifyPropertyChanged("Name");
}
}
public Person(string name) { Name = name; }
}
}
나는 아이템에 대한 약간의 애니메이션을 사용할 것이라고 생각한다. 페이드 인 (flade out) -> removeAt -> insertAt -> 페이드 인 (fade in)과 같이 깜빡임을 볼 수 없으므로 UX는 가능한 한 매끄럽습니다. – michele