Just a thought… Could you have a read only property MyCalcField
that does the calculations on the fly and simply raise PropertyChanged
event for it when underlying data changes? For example, if a child in the
list changes and you need to refresh that field in the root object, you can
call this.Parent.Parent.RefreshCalculatedField where RefreshCalculatedField has
OnPropertyChanged(“MyCalcField”)
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: almostchristian
[mailto:cslanet@lhotka.net]
Sent: Friday, October 03, 2008 2:08 AM
To: Sergey Barskiy
Subject: [CSLA .NET] UI doesn't refresh with calculated fields in
silverlight
I've
been working in a project with silverlight that has a BO with a calculated
field derived from its own fields and another BO with a calculated field that
comes from a BusinessList. In the latter BO, the Performance from its children
is tallied to give the overall performance.
The problem comes in with silverlight. The UI doesn't refresh the controls
bound to the calculated field whenever the fields that the calculated field
depends on is changed. To solve the problem with the first BO, I created a
managed CSLA property to hold the calculated value, and update it when the
fields it depends on changed. It doesn't look natural, and if I'm not careful,
bugs might creep in but it works.
For the second BO with a BusinessList, I also created another managed property
to hold the value but in addition, I needed to override the CopyStateCompleted
and added this code:
protected override
void CopyStateCompleted()
{
base.CopyStateCompleted;
SuccessFactors.ChildChanged +=
(sender, e) =>
SetProperty<decimal>(PerformanceProperty, SuccessFactors.Performance) ;
}
Again, it works well, the UI now updates, but it is not really intuitive.
Is there a better way to achieve the same effect?
almostchristian:The problem comes in with silverlight. The UI doesn't refresh the controls bound to the calculated field whenever the fields that the calculated field depends on is changed. To solve the problem with the first BO, I created a managed CSLA property to hold the calculated value, and update it when the fields it depends on changed. It doesn't look natural, and if I'm not careful, bugs might creep in but it works.
XAML data binding (in WPF and Silverlight) handles the PropertyChanged event differently from Windows Forms.
In Windows Forms, a PropertyChanged event causes all bound elements to refresh.
In WPF and Silverlight, a PropertyChanged event causes elements bound only to the specified property to refresh.
In CSLA .NET for Windows there's a configuration switch you need to set to tell CSLA to work in "XAML mode". In CSLA .NET for Silverlight it only works in XAML mode obviously.
But if you have calculated properties that are bound to a XAML UI, you need to make sure a PropertyChanged event is raised for those calculated properties, or data binding won't refresh the UI.
Copyright (c) Marimer LLC