c# - Observing NotifyPropertyChanged and responding to it -
i have collection of field
objects , each field
object implements inotifypropertychanged
. field object has various properties inside it, have 1 property called isapproved
need listen changes. interest if boolean flag set or unset, need notified or need respond event(the property set or unset ui via wpf binding). can use reactive extensions this, or overkill? if not recommend?
code:
public class field : inotifypropertychanged { private bool _isapproved; public bool isapproved { { return _isapproved; } set { if (_isapproved == value) return; _isapproved = value; raisepropertychanged(() => isapproved); } } ///has lots of other properties. }
in viewmodel, have collection of field
s, , need observe on see when isapproved
property set or unset on or of them. how can that?
edit: have fields collection an observable collection, bound itemscontrol. each item inside field rendered using datatemplate , template selected using template selector. isapproved property bound checkbox in each of datatemplate. have button on page, , onclicking button approved checkboxes should set.i have button tracks state of approvals, if approved, button(submit) should enabled , if of field not approved button should disabled.
if need update ui when property changes, can bind property , you're done (as mentioned @sircodesalot):
<checkbox ischecked="{binding isapproved}" />
if want listen changes programatically, can register propertychanged
event this:
myfield.propertychanged += (sender, e) => { if (e.propertyname == "isapproved") { // stuff } }
Comments
Post a Comment