我有一个静态 IList,它充当静态类中的存储库:
//静态类设置
public static IList RecentSearchedRepo = new ObservableCollection<object>();
和一个位于另一个类中的 IList,我将我的 UI 网格绑定到:
//组件类
private IList recentsearch = new ObservableCollection<object>();
public IList RecentSearch
{
get
{
return recentsearch;
}
set
{
recentsearch = value;
RaisePropertyChanged("RecentSearch");
}
}
我将对象添加到 RecentSearchedRepo :
RecentSearchedRepo.add(searchitem)
然后将RecentSearch设置为静态列表
RecentSearch = Settings.RecentSearchedRepo;
XAML 片段:
<GridLayout:RecentSearchGrid x:Name="recentSearchGrid" ItemsSource="{Binding RecentSearch}" />
扩展 UserControl 的 RecentSearchGrid 类的片段:
public IList ItemsSource
{
get
{
return GetValue(ItemsSourceProperty) as IList;
}
set
{
SetValue(ItemsSourceProperty, value);
}
}
private static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(IList), typeof(RecentSearchGrid), new PropertyMetadata(null, OnItemsSourcePropertyChanged));
private static void OnItemsSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
RecentSearchGrid source = d as RecentSearchGrid;
if (source != null)
{
source.setListforgrid(source.ItemsSource);
}
}
问题是当我将第一项添加到RecentSearchedRepo
UI 时,UI 已更新,但在随后的每次添加中,UI 都不会更新。