I have an observablecollection bound to a datagrid. This collection is populated from a search result. I can also add items to the datagrid. I want to disable rows, that were part of the original collection. The new rows added by me, should be editable. My limitation is that, I cannot have a boolean property in the collection to use in a datatrigger. Is there a way to do it?
Edit: Forgot to mention that I am using a MVVM framework.
If you cannot add "IsEnabled" property to items in your collection you can always create new class which inherits from class/type of those items.
public class MyDataGridPresenterClass : OriginalItemClass
{
public bool IsEnabled { get; set; }
}
And use this new type
in that ObservableCollection
Nothing can stop you from doing this... And of course every MyDataGridPresenterClass
is also OriginalItemClass
since it inherits from it.
So you can have
ObservableCollection<MyDataGridPresenterClass> DataGridItems
{
get { return this.dataGridItems; }
set
{
this.dataGridItems = value;
RaisePropertyChanged("DataGridItems");
}
}
Now You have IsEnabled
property so you can use it in that DataTrigger you mentioned, you didn't modify OriginalItemClass
and everybody is happy. :) And one more thing. Just to be clear :) MVVM is not a framework... MVVM is design pattern. I hope this helps :) Best regards and good luck :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.