c# - Why isn't my background color binding updating? -
ok, sure have setup correctly...
i have grid, shown here:
<grid grid.row="1" grid.column="1" background="{binding crewselbg[1]}">
ok. have following array, here:
private string[] crewselbg; public string[] crewselbg { { return crewselbg; } set { crewselbg = value; onpropertychanged("crewselbg"); } }
i initialise values in array in constructor of viewmodel shown here:
crewselbg = new string[26]; crewselbg = enumerable.repeat("#8a008a00", 26).toarray();
this initialises entire array green colour. (in fact green colour should #00000000 wanted see bound correctly). have checkbox, when clicked activates icommand. here checkbox:
<checkbox grid.column="0" ischecked="{binding crewchecked[1]}" margin="5,0,0,0" command="{binding crewselectcheck}" commandparameter="01"/>
and icommand calls setup here:
private icommand crewselectcheck; public icommand crewselectcheck { { if (crewselectcheck == null) { crewselectcheck = new relaycommand(param => this.crewselectcheckex(param.tostring()), null); } return crewselectcheck; } } public void crewselectcheckex(string p) { if (crewchecked[convert.toint32(p)]) { crewselbg[convert.toint32(p)] = "aliceblue";//selected } else { crewselbg[convert.toint32(p)] = "#00000000"; } }
ok... so... when clicking checkbox , moving checked state, triggers line setting crewselbg[1] aliceblue. put breakpoint on line , indeed trigger line. stepped 1 more line of code, , crewselbg[1] did indeed, change "aliceblue". background of grid stays green, (or whatever value put in constructor).
i dont understand why won't update??? have onpropertyraised event (i tried adding following well, didn't work:
onpropertychanged("crewselbg[1]");
that did nothing either.)
any ideas?
this observablecollection
preferable. should able change string[]
observablecollection<string>
, have work correctly.
you can try onpropertychanged("crewselbg")
if works invalidate of bindings elelements.
Comments
Post a Comment