0

I have a LightSwitch screen which consists of a List containing a CustomControl. This CustomControl has a set of dependency properties which are bound to the properties on the entity through TwoWay bindings.

On one of the dependency properties on the CustomControl I have a PropertyChangedCallback which executes a method on the LightSwitch page. This then runs some calculations across the collection of items the list is bound to.

Most of the time this is fine, however on some occasions it appears that the calculations are run before the change that triggered them are pushed through to the entity from the TwoWay bindings on the CustomControl. How do I resolve this? I need to ensure that the code within the LightSwitch page is run after the change to the CustomControl dependency property is pushed from the TwoWay binding.

Create the binding on the CustomControl by:

     SetBinding(AxleNumberProperty, new Binding("Value.Number") { Mode = BindingMode.TwoWay }); 

Dependency property looks like:

     public static readonly DependencyProperty AxleNumberProperty =
        DependencyProperty.Register("AxleNumber", typeof(int), typeof(AxleViewer), new PropertyMetadata((d, e) => ((AxleViewer)d).RecalculateSquare())); 

My callback on the dependency property looks like:

     private void RecalculateSquare()
    {
        IContentItem contentItem = (IContentItem)DataContext;
        IScreenDetails screenDetails = contentItem.Screen.Details;

        screenDetails.Dispatcher.BeginInvoke(() => screenDetails.Commands["UpdateSquare"].Execute());
    } 

Then within the screen I have:

     partial void UpdateSquare_Execute()
    {
        // perform calculation on this.Axles
    }
Duncan Watts
  • 1,331
  • 9
  • 26

1 Answers1

0

You can check on propertychangedcall back method if there is any change in the property then only execute your code of calculation. Otherwise remove the propertychangedcallback and put your code in the setter of Property.

Cheers! Vinod

vinod8812
  • 645
  • 10
  • 27
  • Sorry I don't think you understand my question. I have two objects which each have a property. Property 1 on object A is bound with TwoWay binding to property 2 on object B. When property 2 on object B is changed, the PropertyChangedCallback executes a method on object A which performs some calculations, however at this point property 1 may or may not have been updated with the change made to property 2. Clear? :) – Duncan Watts Jul 10 '12 at 09:36
  • when property 1 of object is bound with two way of property 2 of object B it will change once Property2 is changed of object B.What is your problem please I don't think I have understood where are you stuck? – vinod8812 Jul 12 '12 at 07:28
  • The issue is that property 1 of object A *is not updated* at the point the PropertyChangedCallback is run when updating property 2 of object B. Within the callback I am using a Dispatcher, which is required by LightSwitch, which results in a race condition, sometimes the property has been updated, sometimes not. I am asking if there is a way to force through the update to object A. – Duncan Watts Jul 12 '12 at 10:27