c# - Multibinding with convertback does not work when one converted value in UnsetValue -


i have following multibinding:

 <grid.visibility>     <multibinding converter="{staticresource mymultivalueconverter}" mode="twoway">       <binding relativesource="{relativesource templatedparent}" path="myvisibilitydependencyproperty" mode="twoway"/>       <binding relativesource="{relativesource templatedparent}" path="myboolproperty" mode="twoway"/>    </multibinding> </grid.visibility> 

myvisibilitydependencyproperty dependency property. myboolproperty normal property. implementation of mymultivalueconverter important thing:

public class mymultivalueconverter: imultivalueconverter {     public object convert(object[] values, type targettype, object parameter, cultureinfo culture)     {        //not interesting     }      public object[] convertback(object value, type[] targettypes, object parameter, cultureinfo culture)     {         return new[] { value, binding.donothing};     } } 

now scenario: smth. triggers call of convertback-method, means hit break point there. afterwards hit break point in onpropertychangedcallback of myvisibilitydependencyproperty. there can see new value of myvisibilitydependencyproperty value set in convertback-method.

now issue not understand. change implementation of convertback-method to:

public object[] convertback(object value, type[] targettypes, object parameter, cultureinfo culture)     {         return new[] { value, dependencyproperty.unsetvalue};     } 

now follow exact same scenario. smth. triggers call of convertback-method, means hit break point there. after nothing happens. onpropertychangedcallback not called , myvisibilitydependencyproperty not updated. why?

it seems if 1 of values in array dependencyproperty.unsetvalue, propagation of values stopped. not value values in array. supported following behavior:

return new[] { binding.donothing, false }; 

this results in call of setter of myboolproperty.

return new[] { dependencyproperty.unsetvalue, false }; 

this not call setter of myboolproperty.

i not find hints of explanation in documentation , not make sense in opinion.

i not find hints of explanation in documentation , not make sense in opinion.

i don't recall ever seeing in documentation, observations correct:

if any element in result of imultivalueconverter.convertback unsetvalue, entire set of proposed values rejected, i.e., conversion fails, , none of child bindings have source values updated.

the relevant code can found in multibindingexpression class. below abbreviated excerpt.

internal override object convertproposedvalue(object value) {     object result;     bool success = convertproposedvalueimpl(value, out result);     {         result = dependencyproperty.unsetvalue;         ...     }     return result; }  private bool convertproposedvalueimpl(object value, out object result) {     result = getvaluesforchildbindings(value);      object[] values = (object[])result;     int count = mutablebindingexpressions.count;     bool success = true;      // use smaller count     if (values.length < count)         count = values.length;      (int = 0; < count; ++i)     {         value = values[i];         ...         if (value == dependencyproperty.unsetvalue)             success = false; // if element unsetvalue, conversion fails         values[i] = value;     }      result = values;     return success; } 

as whether makes sense, think does. value of donothing in result array indicates corresponding child binding should skipped, i.e., source value should not updated. this, in effect, provides mechanism partial updates. if think it, scenarios care are:

  1. all sources updated successfully
  2. some sources updated successfully
  3. total failure: no sources updated

the normal behavior provides (1), , use of donothing can satisfy (2). arguably makes sense use unsetvalue indicate total failure. consistent meaning single-value converters: unsetvalue means conversion failed. difference convertback returns object[], cannot return unsetvalue directly. can, however, return array containing only unsetvalue: since presence means entire result gets thrown out, array length doesn't have match number of child bindings.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -