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
}