0
ObservableCollection
の実装のいくつかを検索しました。サービスを開始するときにADDが起動するイベントが発生しましたが、コールを行い、リストのオブジェクトのプロパティを更新すると、コレクションは通知もトリガーもしません。ObservableCollectionはCollectionChnagedを生成しません
ObservableCollection
ハンドラです。
public class iGamingObservableCollection
{
ObservableCollection<GameInstance> _contentList;
public iGamingObservableCollection()
{
_contentList = new ObservableCollection<GameInstance>();
_contentList.CollectionChanged += ContentCollectionChanged;
}
public ObservableCollection<GameInstance> ContentList
{
get { return _contentList; }
}
public void ContentCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Remove)
{
foreach (GameInstance item in e.OldItems)
{
Console.WriteLine("removed: State is now: " + item.InstanceState);
//Removed items
}
}
else if (e.Action == NotifyCollectionChangedAction.Add)
{
foreach (GameInstance item in e.NewItems)
{
Console.WriteLine("added: State is now: " + item.InstanceState);
//Added items
//item.PropertyChanged += InstancePropertyChange;
}
}
else if (e.Action == NotifyCollectionChangedAction.Replace)
{
foreach (GameInstance item in e.NewItems)
{
Console.WriteLine("changed: State is now: " + item.InstanceState);
//Changed items
//item.PropertyChanged += InstancePropertyChange;
}
}
else if (e.Action == NotifyCollectionChangedAction.Replace)
{
foreach (GameInstance item in e.OldItems)
{
Console.WriteLine("changed: State is now: " + item.InstanceState);
//Changed items
//item.PropertyChanged += InstancePropertyChange;
}
}
}
ObservableCollection
コントローラ
public class InstanceManagerService : IInstanceManager
{
//TODO: FIX THAT CLASS.. THIS IS INITIAL IMPLEMENTATION!!!
IGameInstanceRepository instanceRepository;
iGamingObservableCollection notifyList = new iGamingObservableCollection();
//private Timer updateNotifierTimer;
public InstanceManagerService(IGameInstanceRepository instanceRepository)
{
this.instanceRepository = instanceRepository;
populateNotifyList();
//updateNotifierTimer = new Timer((e) => { populateNotifyList(); }, null, 120 , (int)(TimeSpan.FromMinutes(2).TotalMilliseconds));
}
private void populateNotifyList()
{
var list = instanceRepository.getInstances();
foreach (var l in list)
{
notifyList.ContentList.Clear();
notifyList.ContentList.Add(l);
}
Console.WriteLine("Notify list content updated.");
}
public bool releaseInstance(Guid instanceId)
{
if (instanceRepository.UpdateGameInstanceToFree(instanceId))
{
var notifyTask = notifyList.ContentList.Where(g => g.Id == instanceId).FirstOrDefault();
notifyTask.InstanceState = InstanceState.Free;
return true;
}
return false;
}
しかし、何とかそれは動作を停止し、私はこれで終わった。私はINotifyPropertyChangedを実装しているモデルを元に戻そうとします。 – vLr