Reputation: 4332
I have a custom control that inherits from a datagrid. I have to evaluate a property each time the data is bound the grid. I am currently binding using DataSource="{Binding....}"
Is there a way that I can create a new dependency property (?) which which will be evaluated each time the DataSource property is changed? Can I somehow "attach" my method to the DataSource Property?
I hope my intent is clear.
Thanks for any thoughts.
Upvotes: 0
Views: 361
Reputation: 4332
I was able to handle this by overriding OnPropertyChanged and using the following code along with my new dependencyproperty -
if(e.Property.Name = "DataSource")
{
// Invoke my new method
}
Upvotes: 0
Reputation: 42374
If you are inheriting from DataGrid
, you can just override the OnItemsSourceChanged
method, like this:
protected override void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
{
// update your property here
base.OnItemsSourceChanged(oldValue, newValue);
}
Upvotes: 1