0

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.

czuroski
  • 4,316
  • 9
  • 50
  • 86
  • possible duplicate of [Listen to changes of dependency property](http://stackoverflow.com/questions/4764916/listen-to-changes-of-dependency-property) – H.B. Jun 07 '12 at 18:28

2 Answers2

1

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);
}
devuxer
  • 41,681
  • 47
  • 180
  • 292
  • I am actually using an Infragistics datagrid, so the OnItemsSourceChanged isn't available. I will see if there is anything similar there. – czuroski Jun 07 '12 at 18:42
0

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
}
czuroski
  • 4,316
  • 9
  • 50
  • 86