.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
[ObservableObject]
public partial class MyViewModel : ViewModel
{
public ObservableCollection<DataType> SelectedItems { get; } = [];
}
results in error:
CS0200 Property or indexer "cannot be assigned to" "it is read only"
in the owner of the MyViewModel:
private void UpdateTwoWay_5_ItemsSource()
{
if (this.initialized)
{
if (this.dataRoot != null)
{
if (this.dataRoot.ViewModel != null)
{
if (this.dataRoot.ViewModel.MyViewModel!= null)
{
// Error here
this.dataRoot.ViewModel.MyViewModel.SelectedItems = (global::System.Collections.ObjectModel.ObservableCollection<global::Abc>)this.obj5.ItemsSource;
}
}
}
}
}
Regression
No response
Steps to reproduce
1. Do the above.
I'm using NuGet package: CommunityToolkit.Mvvm 8.2.2
Expected behavior
As I understand it, with collections you don't use, e.g., a List marked with ObservableProperty, you just do it the standard way with an ObservableCollection, and therefore it is only assigned once. So it should work to not have a setter.
Screenshots
No response
IDE and version
VS 2022
IDE version
Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.9.2
Describe the bug
This code
results in error:
in the owner of the
MyViewModel
:Regression
No response
Steps to reproduce
Expected behavior
As I understand it, with collections you don't use, e.g., a
List
marked withObservableProperty
, you just do it the standard way with anObservableCollection
, and therefore it is only assigned once. So it should work to not have a setter.Screenshots
No response
IDE and version
VS 2022
IDE version
Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.9.2
Nuget packages
Nuget package version(s)
8.2.2
Additional context
Adding a setter seems to make everything work.
Help us help you
No, just wanted to report this