Binding ObservableCollection in version 3.2.7
Hi,
Binding ObservableCollection<NodeComponent> to ObservableCollection<BaseComponent> in version 3.2.7 does not work
How to fix this correctly for version 3.2.7?
Binding ObservableCollection<NodeComponent> to ObservableCollection<BaseComponent> in version 3.2.7 does not work
Code: Select all
struct NodeComponent: public BaseComponent {};-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Binding ObservableCollection in version 3.2.7
Hi,
In previous versions there was a bug that made all observable collections share the same type, which will incorrectly allow you to cast between unrelated types.
Although it might seem that ObservableCollection<NodeComponent> and ObservableCollection<BaseComponent> are related, that is not the case because they don't inherit one from the other. So either you define your control property to use the same type as the bound property or a base type like BaseObservableCollection. Or make sure that the bound property returns a collection of the same type as the control property.
In previous versions there was a bug that made all observable collections share the same type, which will incorrectly allow you to cast between unrelated types.
Although it might seem that ObservableCollection<NodeComponent> and ObservableCollection<BaseComponent> are related, that is not the case because they don't inherit one from the other. So either you define your control property to use the same type as the bound property or a base type like BaseObservableCollection. Or make sure that the bound property returns a collection of the same type as the control property.
-
- KeldorKatarn
- Posts: 243
- Joined:
Re: Binding ObservableCollection in version 3.2.7
As a side note: While not recommended, if you have a use-clase where you absolutely NEED to change the type of the collection items, check github. There's some implementations for synchronized ObservableCollection where you can pass a Func that converts one type to another and the collection will keep itself in sync with the source collection (edge case use case though, it's best to keep the types identical if at all possible)Ok,
Thanks
Re: Binding ObservableCollection in version 3.2.7
Ok, Thank you for your answer.As a side note: While not recommended, if you have a use-clase where you absolutely NEED to change the type of the collection items, check github. There's some implementations for synchronized ObservableCollection where you can pass a Func that converts one type to another and the collection will keep itself in sync with the source collection (edge case use case though, it's best to keep the types identical if at all possible)
-
- KeldorKatarn
- Posts: 243
- Joined:
Re: Binding ObservableCollection in version 3.2.7
Specifically these might be useful to you: https://github.com/Cysharp/ObservableCollections/Ok, Thank you for your answer.As a side note: While not recommended, if you have a use-clase where you absolutely NEED to change the type of the collection items, check github. There's some implementations for synchronized ObservableCollection where you can pass a Func that converts one type to another and the collection will keep itself in sync with the source collection (edge case use case though, it's best to keep the types identical if at all possible)
Who is online
Users browsing this forum: Bing [Bot] and 2 guests