Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Silverlight TV 44: Top Four Questions from the WCF RIA Services Forum
Sep 15, 2010 at 2:40 PMAgain, this probably isn't the best solution, but really for derived properties like that, you'll need to notify upstream whenever you change. One approach is to create a 'ExtendedPrice' type column on your LineItem entity which does the UnitPrice * Quantity calculation, then use the OnUnitPriceChanging/OnQuantityChanging methods to fire change notifications for your ExtendedPrice property. Then you'd need to enhance the CollectionChanged handler to also attach handlers for the OnPropertyChanged events of the child objects and fire your Total changed event from there.
HOWEVER, you may begin to wonder if this type of behavior is something you want built into your MODEL, or if you want to build it into your VIEWMODEL [assuming you're using MVVM]. If you want it built into your VIEWMODEL, then you can actually create a 'smart' observable collection that handles attaching to the contained items OnPropertyChanged events and do things that way, then have your smart collection be what is exposed in your VIEWMODEL and bound.
Once you've done the above, then you could potentially extend that collection to give you your total price as an event on change, as an actual observable property of the smart collection, etc, you really open up the options. RIA services, when using the model natively on the client, can really be a limitation for extension, and if you want rich UIs, you'll often find yourself binding NOT to the LineItems collection hanging off your Order object, but rather to a LineItems collection hanging off your OrderViewModel or some such that gives you more flexibility.
A third option, which feels very 'smelly' would be to somehow invoke the Order object's PropertyChanged event FROM the LineItem class through the navigation property, so when unit price or quantity changes, the line item causes the Order's property change notification to fire explicitly if the associated Order navigation property is non-null... Not necessarily good design, but certainly feasible.
Silverlight TV 44: Top Four Questions from the WCF RIA Services Forum
Sep 14, 2010 at 11:57 AMThis scenario requires a little more work client-side, but you can capture the CollectionChanged event from your child collections to surface this kind of functionality. Keep in mind that you should probably look at the WeakEventListener patterns out there to do this in a more 'appropriate' fashion. This code is also thrown together 'off the cuff', so there may be syntactical errors as well.
public partial class Order { /// ... code partial void OnCreated() { LineItems.CollectionChanged += (s, e) => { RaisePropertyChanged("Total"); }; } public decimal Total { get { return (decimal)LineItems.Select(i => i.UnitPrice * i.Quantity).Sum(); } } }Countdown to PDC10: There’s one pass left! Is your name on it?
Aug 17, 2010 at 10:52 AMI'd love to get a ticket to the event. I've done the streaming at the the MIX events, but the 'in person' view just can't be beat. Plus, PDC10 is very near my birthday!