c# - WPF - cascading ComboBoxes, dependent ones don't update -
i have 3 comboboxes such c's items list dependent on selected item in b , b's items list dependent on selected item in a. have observablecollections of particular classes itemssource on each combobox, , want name property of selected item pushed property in class. example:
observablecollection<aclass> items => itemssource of cbo_a combobox and selectedinstanceofaclass.name should pushed data.aclassname property. problem have when choose value in combobox first time, b combobox gets appropriate items based on selected item in a, expected. same when select item in b first time--c gets right items. however, when choose different value in a, items in b updated selected value of b stays same, , when try select new value in b new items, selection doesn't change--it stays same selected value selected in b.
here's xaml have right now:
<combobox x:name="cbo_a" itemssource="{binding path=lists.aitems, mode=oneway}" displaymemberpath="name" selectedvaluepath="name" selectedvalue="{binding path=data.aclassname, validatesondataerrors=true, mode=onewaytosource}" /> <combobox x:name="cbo_b" itemssource="{binding elementname=cbo_a, path=selecteditem.bitems, mode=oneway}" selectedvaluepath="name" displaymemberpath="name" selectedvalue="{binding path=data.bclassname, validatesondataerrors=true, mode=onewaytosource}"/> <combobox x:name="cbo_c" itemssource="{binding elementname=cbo_b, path=selecteditem.citems, mode=oneway}" selectedvaluepath="name" displaymemberpath="name" selectedvalue="{binding path=data.cclassname, mode=onewaytosource, validatesondataerrors=true}" /> what causing weird behavior selected value not updating when explicitly click combobox , try change value?
edit: when debugging , had selectionchanged handler on cbo_a , on cbo_b, entered cbo_b handler before cbo_a one, selected item b's perspective still old item, because had not been updated yet. :/
edit 2: if flip order of comboboxes in xaml, suggested this question, such c comes before b comes before a, enter a's handler first. when enter handler cbo_b, selecteditem property shows old value (previously selected, before chose new value in cbo_a), though clicked value new list of items showing in combobox.
edit 3: i'm trying version of this answer , getting same problem: see new values in combobox b upon changing selected value of combobox a, cannot change selected value in b after i've set once. i'm beginning think i've got else going awry.
wow. so, don't go implementing bunch of iequatable<t> equals methods new classes, because may end doing did:
if (referenceequals(this, other)) { return false; // what?? } sigh. got comboboxes work by:
- correcting
bclass.equals(bclass other)method; - using this answer having view model class different properties
selectedaitem,aitems; and - using this answer putting xaml declarations in different order
cbo_ccomes beforecbo_b,cbo_bcomes beforecbo_a.
i may try simplifying things , see parts absolutely necessary comboboxes.
Comments
Post a Comment