wpf - PropertyChangedTrigger For Multiple Properties? -
is there way create propertychangedtrigger multiple properties share same conditions, sake of redundancy, without specifying conditions repeatedly each propertychangedtrigger?
for example, when propertya, propertyb , propertyc change, want command execute in viewmodel.
i thinking of extending propertychangedclass , adding dependency property of observable collection of bindings. turned out i'm not knowledgeable in how bindings monitored.
then saw of old code , saw multibinding. thought work. , did multivalueconverter increments static field. i'm not sure if best solution worked.
first multivalueconverter:
public class incrementonpropertychangedmulticonverter:imultivalueconverter { static uint _counter=0; #region imultivalueconverter members public object convert(object[] values, type targettype, object parameter, system.globalization.cultureinfo culture) { _counter = _counter < uint.maxvalue ? _counter + 1 : 0; return _counter; } public object[] convertback(object value, type[] targettypes, object parameter, system.globalization.cultureinfo culture) { throw new notimplementedexception(); } #endregion }
then in xaml add multibinding instead of binding in propertychangedtrigger.
<i:interaction.triggers> <ei:propertychangedtrigger> <ei:propertychangedtrigger.binding> <multibinding converter="{staticresource incrementonpropertychangedmulticonverter}"> <binding path="property1" /> <binding path="property2" /> <binding path="propertyn" /> </multibinding> </ei:propertychangedtrigger.binding> <i:interaction.behaviors> <ei:conditionbehavior> <ei:conditionalexpression> <ei:comparisoncondition leftoperand="{binding property1}" operator="equal" rightoperand="{binding property2}" /> </ei:conditionalexpression> </ei:conditionbehavior> </i:interaction.behaviors> <ei:changepropertyaction propertyname="background" value="transparent" /> </ei:propertychangedtrigger> <i:interaction.triggers>
Comments
Post a Comment