c# - How to change the appearance of any control when property changes? -
i'd highlight user has been modified, know have changed or has been programatically changed behind scenes them.
i want use styles apply logic controls, i'm not sure how. know need create trigger not sure trigger on or how pick changes bound property in order know if it's changed or not.
thanks.
probably best approach involves writing wrapper class values implements inotifypropertychanged
, exposes read/write value
property of type object
, boolean valuehaschanged
property. can change tracking pretty in value
setter:
if (!value.equals(_value)) { _value = value; valuehaschanged=true; onpropertychanged("value"); }
instead of view model class exposing string
or datetime
properties, should expose valuewrapper
properties wrap internal fields, e.g.:
private string somestringfield; private valuewrapper _somestringproperty; public valuewrapper somestringproperty { { return (_somestringproperty == null) ? _somestringproperty = new valuewrapper(somestringfield) : _somestringproperty; } }
then can build style like:
<style x:key="showchangedvalue"> <setter property="background" value="white"/> <style.triggers> <datatrigger binding="{binding valuehaschanged}" value="true"> <setter property="background" value="aliceblue"/> </datatrigger> </style.triggers> </style>
and use like:
<textbox datacontext="{binding somestringproperty}" text="{binding value, mode=twoway}" style="{staticresource showchangedvalue}"/>
there annoying things this, fact change property's value inside main view model class have use somestringproperty.value = "foo"
instead of somestringproperty = "foo"
.
Comments
Post a Comment