私はバインドするリストボックスを持っていますHistoryItems
、HistoryItems
はObservableCollection
のHistory
です。ここ は、リストボックスの宣言である:ここで私のリストボックスは更新されません
<ListBox x:Name="RecentListBox" SelectionChanged="RecentListBox_SelectionChanged" ItemsSource="{Binding HistoryItems,Converter={StaticResource HistoryValueConverter} }" ItemsPanel="{StaticResource ItemsPanelTemplate1_Wrap}" ItemTemplate="{StaticResource RecentViewModelTemplate}">
はHistory
クラスです:私は、アプリを起動すると
public class History : INotifyPropertyChanged
{
public History() { }
int _id;
string _date;
string _url;
string _name;
public History(int id, string date,string url,string name)
{
this.id = id;
this.date = date;
this.url = url;
this.name = name;
}
public int id
{
get
{
return _id;
}
set
{
if (value != _id)
{
_id = value;
NotifyPropertyChanged("id");
}
}
}
public string date
{
get
{
return _date;
}
set
{
if (!value.Equals(_date))
{
_date = value;
NotifyPropertyChanged("string");
}
}
}
public string url
{
get
{
return _url;
}
set
{
if (!value.Equals(_url))
{
_url = value;
NotifyPropertyChanged("url");
}
}
}
public string name
{
get
{
return _name;
}
set
{
if (!value.Equals(_name))
{
_name = value;
NotifyPropertyChanged("name");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
// App.viewModel.HistoryItems = (App.Current as App).dataHandler.retrieveHistory_DB();
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
リストが読み込まれますが、私はいくつかのピボットの子供たちにいくつかのmodifsを行った後、と行きますバックメインパノラマビューに、私はOnNavigatedTo
でHistoryItems
を更新しよう:
App.ViewModel.HistoryItems = (App.Current as App).dataHandler.retrieveHistory_DB();
が、LIS tboxは更新されず、関数は正しいデータを返します。何が問題なの? History
はINotifyPropertyChanged
であり、HistoryItems
はObservableCollection<History>
なので、問題はありません。リストを更新しない原因は何ですか?
ないようにViewModel.HistoryItems用セッターを書き換え
–HistoryItems