wpf - ComboBox SelectedValue not changing from binding to Dependency Property -
i have custom control:
i don't want specifics simplicity's sake have 3 dependency properties :
mycustomcontrol (cs) :
public class mycustomcontrol : control { dp value1 dp internalvalue dp selectedvalue onvalue1changed() { internalvalue = calculatebasedon1(); } static bool _issetinternally; oninternalvaluechanged() { if(condition()) { _issetinternally = true; selectedvalue = e.newvalue; } else { value1 = fixvalue1(); } } onselectedvaluechanged() { if(_issetinternally) { _issetinternally = false; return; } value1 = extractvalue1frominput(e.newvalue); } public list<string> values { get{ return new list<string>() { "1","2",......,"200"};} } }
my controltemplate (again simplified) :
<controltemplate> <combobox x:name="cb" itemssource="{binding relativesource={relativesource templatedparent}, mode=oneway, path=values}" selecteditem={binding relativesource={relativesource templatedparent}, path=value1, mode=twoway, updatesourcetrigger=propertychanged} </controltemplate>
the problem : cb showing last value chosen , after fixed explained below .
flow :
1) input :
1.1) selectedvalue bound property in datacontext , receives value.
1.2) onselectedvaluechanged() sets value1.
1.3) value1 sets "cb" selecteditem via binding.
1.4) onvalue1changed sets internalvalue.
1.5) oninternalvaluechanged() flags _issetinternally = true , updates selectedvalue.
1.6) onselectedvaluechanged() zeros _issetinternally = false , stops flow (return).
2) output :
2.1) cb's selecteditem changed.
2.2) value1 set via binding.
2.3) onvalue1changed() sets internalvalue.
2.4) if condition met propagate output.
2.4.1) go (1.4)
2.4.2) problem , condition not met, set value1 again valid value.
2.5) go (1.4)
the problem in 2.4.2 combobox still showing non - valid value chosen in (2.1)
observing snoop can see selecteditem correct , have been changed , selectedvalue , selectedindex still one's chosen before fix.
*further more iv'e attempted coerce value1 on coercion callback , had same effect.
any idea's why combobox doesn't update it's value via binding in scenario ?
i don't know if did understand problem, should have binding selecteditem in combobox.
when value changes, should raise propertychanged event inotifypropertychanged.
in combo, have properties displaymemberpath , selectedvaluepath.
can work it?
regards,
Comments
Post a Comment