ObservableCollections
ObservableCollections copied to clipboard
WPF example is behaving weirdly
Hi there,
First let me thank you for the massive and impressive work you did with this library! Observable collections are really something that should get more love in the .Net ecosystem :)
I noticed something strange with the WPF example that you provide. When I run it locally and press a few times on the "Insert" button, I get the following :

The first 3 lines (in red) correspond to the initial items inserted via AddRange and is the tuple (value, view), while the rest (in green) has been added by pressing the "Insert" button and is only the value.
I do not understand why there is a difference, do you have any idea what could be the reason?
I'm also questioning yielding tuples (value, view) when enumerating, instead of only views. Tuples cannot be used directly for <ListView ItemSource={...} />. Is there a reason for this choice?
SynchronizedView<T, TView> が通知する NotifyCollectionChangedEventArgs<T> が T 型のため WPF に渡される要素も T 型になっているのが原因のように思われます。
NotifyCollectionChangedEventHandler<TView> として TView 型コレクションの変更イベントにしてやるとうまくバインドされました。やっつけ実装
ビューが (T value, TView view) のタプルになっている理由はフィルタメソッドで両方見たいからではと推測しましたが、元コメントにあるように WPF で直接バインドできないのは不便に感じました。
※試してませんが NotifyCollectionChangedEventHandler<(T, Tvalue)> としたら Item2.~ で取れたりするのでしょうか。
-- In English (Google Translate)
It seems that the element passed to WPF is also T type because NotifyCollectionChangedEventArgs<T> notified by SynchronizedView<T, TView> is T type.
By modifying the type parameter to NotifyCollectionChangedEventHandler<TView>, it was successfully bound to a TView type collection change event. Rough implementation
I guess the reason the view is a tuple of (T value, TView view) is because it's convenient to be able to see both values in the filter method, but as the original comment says, it can't be bound directly in WPF. I felt inconvenient.
- I haven't tried it, but if the type parameter is modified to NotifyCollectionChangedEventHandler<(T, Tvalue)>, can I get it with Item2.~ ?
ありがとうございます、そのとおりですね、このままではあまりに不便というのはもっともです……! いただいた案も含め、ちょっと考えてみたいです。
You're right, it's too inconvenient as it is. I'll consider about it.
こんな感じで書けるような、別の案を考えてみました。実装 google translate) I came up with another idea that could be written as:
ItemsView = list
.ToSynchronizedCoupleView(x => $"({x}, {x}$)") // IReadOnlyCollection<(T, TView)> -NotifyCollectionChangedEventHandler<(T, TView)>
.ToSynchronizedSingleView() // IReadOnlyCollection<TView> -NotifyCollectionChangedEventHandler<TView>
.WithINotifyCollectionChanged(); // IReadOnlyCollection<TView>, INotifyCollectionChanged, INotifyPropertyChanged
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Could we reopen this issue? It was stale but the issue still exists.
sorry for no longer repond it, I'll check it.