Tuesday, December 28, 2010

Having a setter for an Observable Collection

Here's another cool way to override the getter for an observable collection without breaking your MVVM:


private ObservableCollection<string> _AvailableColumns = new ObservableCollection<string>();
        public ObservableCollection<string> AvailableColumns
        {
            get { return _AvailableColumns; }
            set
            {
                _AvailableColumns.Clear();
                foreach (var item in value)
                {
                    _AvailableColumns.Add(item);
                }
            }
        }

Now you can use it like :


new RequiredColumn() {RequiredColumnName="BSC",DefaultValue="",AvailableColumns=AvilableColumns};


and it will not break your notification changes :)

No comments:

Post a Comment