silverlight - Force reevalution of guard methods in Caliburn Micro -



silverlight - Force reevalution of guard methods in Caliburn Micro -

i have itemscontrol has move up, move down, , delete button in each item (via template). itemscontrol source binds collection of items model datacontracts/pocos (not vms).

i've attached caliburn message handler in main page's view model.

<button cal:message.attach="moveup($datacontext)" >up</button> <button cal:message.attach="movedown($datacontext)" >down</button>

i believe had explicit cal:message.attach , not rely on convention because within itemtemplate.

view model:

observablecollection<item> mycollection = new observablecollection<item>(); //item class simple -- has string name property public bool canmoveup(item item) { var index = mycollection.indexof(item); homecoming index > 0; } public void moveup(item item) { var index = mycollection.indexof(item); if (index > 0) { mycollection.remove(item); mycollection.insert(index - 1, item); } } public bool canmovedown(item item) { var index = mycollection.indexof(item); homecoming index > -1 && index < class1.count - 1; } public void movedown(item item) { var index = mycollection.indexof(item); if (index > -1 && index < class1.count - 1) { mycollection.remove(item); mycollection.insert(index + 1, item); } }

the first item's button disabled. when move downwards first item, 2nd item becomes first item, button not automatically disabled. how forcefulness reevaluation of canmoveup guard method?

in moveup , movedown methods, can notify ui bindings canmoveup/down have been invalidated using notifyofpropertychanged(() => this.canmoveup); (or this.canmovedown appropriate).

this assuming viewmodel derives screen, conductor, or propertychangedbase should.

update

what you'll want refactor code bind selecteditem of listbox property on view model of type item. in fact, caliburn.micro you, if listbox has x:name="items" example, property called selecteditem (there other conventions searches for). then, canmoveup/down methods can properties instead check selecteditem property, , hence can utilize notifyofpropertychanged() invalidate bindings.

silverlight mvvm caliburn.micro

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -