I am binding a DataGrid to an ObservableCollection as:
<DataGrid ItemsSource="{Binding Path=MyCollection, Mode=TwoWay}">
The property in the viewmodel looks like:
public ObservableCollection<MyType> MyCollection
{
get { return this.Model.Collection; }
set { /* Empty but needed for data binding */ }
}
The set accessor for MyCollection is never called or used but is required by the TwoWay DataBinding. The contained Model class initializes Collection at construction because it is required to place the object in a valid state. Is there anyway to get around this unnecessary accessor or are there any alternatives to this?
Set the Mode=OneWay and you don’t need a set.