Accessing the "click" action of a datagridcheckbox column

Accessing the "click" action of a datagridcheckbox column

Old forum URL:

pegesaka posted on Sunday, November 18, 2012

I am trying to get my head around the wpf way of doing things, as well as being a bit of a newbee on CSLA 4, so please excuse me.

I have a DatagridCheckBoxColumn bound to a boolean property in a CSLA editable child object. I am trying to trap when the user changes the checked status of the checkbox (with either mouse or spacebar - the old "Click" event), but there is no click event on the checkbox column, nor the datagrid. So I figure I should be reacting to changes in the bound object, rather than the UI. So I try to tap into the PropertyChanged event but notice that this is protected and not accessable in the wpf window class (different assembly).

I simply want the form to do something when the user changes the checked status, or the business object property changes. Can anyone point me in the right direction please?



JonnyBee replied on Sunday, November 18, 2012

You can access the OnPropertyChanged (and other events) by casting the object to the actual Interface.

Here is how Csla.Xaml.ViewModelBase ataches itelf to a BO (here newValue):

      // hook events on new value
      if (newValue != null)
        var npc = newValue as INotifyPropertyChanged;
        if (npc != null)
          npc.PropertyChanged += Model_PropertyChanged;
        var ncc = newValue as INotifyChildChanged;
        if (ncc != null)
          ncc.ChildChanged += Model_ChildChanged;
        var nb = newValue as INotifyBusy;
        if (nb != null)
          nb.BusyChanged += Model_BusyChanged;
        var cc = newValue as INotifyCollectionChanged;
        if (cc != null)
          cc.CollectionChanged += Model_CollectionChanged;

pegesaka replied on Wednesday, November 21, 2012

Thanks for that JonnyBee.
I can work with the timing (event occurs when the list's selectedIndex is changed or datagrid looses focus), and I spose this is the WPF way of doing things (being controlled by the bound object rather than the UI), but it does seem strange that there is no OnClick, especially for a CheckBox. If you wanted something to occur on the UI as a result of the checkbox changing state as the user changes it, how can you get access to this event? Just curious.

Copyright (c) Marimer LLC