I'm binding to an Xceed DataGridControl (Community Edition) with AutoCreatedColumns
ObservableCollection<ItemViewModel> Items
I would like to mark the created columns' ReadOnly property based on the Editable attribute on the viewmodel property.
class ItemViewModel : ViewModelBase {
[Editable(false)]
public string Id { get; set; }
string _comment;
[Editable(true)]
public string Comment {
get { return _comment; }
set {
_comment = value;
NotifyOfPropertyChanged(() => Comment);
}
// Other properties ...
}
Is this possible? or is there another way I could hook into the creation of the column to inspect the property that is being bound and programmatically set ReadOnly?
I think the optimal solution is to just hook up to
ItemsSourceChangeCompletedevent like this:Alternatively, you could bind the cell
ReadOnlyproperty to your editable attribute as described here.If you know what columns you want to display you could simplify the solution above and bind the column
ReadOnlyproperty like this:But then, you might as well turn off
AutoCreateColumnsand define theColumnscollection by yourself in code (or turn offAutoCreateItemPropertiesand create your ownDataGridCollectionViewSourcewhere you set eachDataGridItemProperty.IsReadOnlyappropriately).