コントロールはINotifyPropertyChanged
でのみ受信し、ICollectionChanged
では受信しないため、これは正常な動作です。コレクションプロパティ自体は変更されないため、コントロールはリフレッシュする必要があることを認識しません。
コレクションの変更をコントロールに渡すには、CollectionChanged
イベントの登録をObservableCollection
にしてから、コレクションが変更されたときにコレクションプロパティのプロパティ変更イベントを発生させる必要があります(アイテムの追加、削除、移動、またはコレクションがクリアされた場合)。
#region [BViewModelCollection]
/// <summary>
/// The <see cref="BViewModelCollection" /> property's name.
/// </summary>
public const string BViewModelCollectionPropertyName = "BViewModelCollection";
private ObservableCollection<BViewModel> _bViewModelCollection = new ObservableCollection<BViewModel>();
/// <summary>
/// Gets the BViewModelCollection property.
/// TODO Update documentation:
/// Changes to that property's value raise the PropertyChanged event.
/// This property's value is broadcasted by the Messenger's default instance when it changes.
/// </summary>
public ObservableCollection<BViewModel> BViewModelCollection {
get {
return _bViewModelCollection;
}
set {
if (_bViewModelCollection != value) {
SetBViewModelCollection(value);
RaisePropertyChanged(BViewModelCollectionPropertyName);
}
}
}
private void SetBViewModelCollection(ObservableCollection<BViewModel> value) {
if (_bViewModelCollection != null)
_bViewModelCollection.CollectionChanged -= this.BViewModelCollection_CollectionChanged;
_bViewModelCollection = value;
if (_bViewModelCollection != null)
_bViewModelCollection.CollectionChanged += this.BViewModelCollection_CollectionChanged;
}
private void BViewModelCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) {
RaisePropertyChanged(BViewModelCollectionPropertyName);
}
#endregion
あなたは今ObservableCollection
を設定し、自動的に収集するためにPropertyChanged
イベントを上昇させることなく、イベントを正しく登録するSetBViewModelCollection
を使用することができます - 例えばコンストラクタまたはロードデータメソッドでの使用のために。
アイテムがコレクションに追加されたり、コレクションから削除されたりすると、コレクションの推移が変更されたことをコントロールに通知する必要があります。
注:メソッド名を独自のフレームワークに調整します。
ご連絡ありがとうございました!私はそれを試してみましょう! – user1149223