c# - Disabling multiple controls depending on a state -
i'm new both caliburn , wpf, excuse me if rather trivial question.
the scenario following: have multiple controls (like buttons , textboxes - latter important part). state (enabled/disabled) dependent on boolean property.
the first suggested method tried using can[functionname] convention , notifyofpropertychange(() => can[functionname]). worked button, did not work textbox.
how bind isenabled property state without using code-behind of view?
the code tried in viewmodel didn't work textbox:
private bool _buttonenablestate = true; public bool buttonenablestate { { return _buttonenablestate; } set { _buttonenablestate = value; notifyofpropertychange(() => canthebutton); notifyofpropertychange(() => canthetextbox); } } public bool canthebutton { { return buttonenablestate; } } public void thebutton() { } public bool canthetextbox { { return buttonenablestate; } }
from view:
<button x:name="thebutton" content="this button" ... /> <textbox x:name="thetextbox" ... />
thanks in advance!
have tried obvious?:
<button content="this button" isenabled="{binding buttonenablestate}" /> <textbox x:name="thetextbox" isenabled="{binding buttonenablestate}" />
update >>>
so, continuing conversation comments... have public
property in appviewmodel
class , instance of class set datacontext
of view contains button
, textbox
controls?
let's see if binding
really working or not... try changing code this:
<button content="{binding buttonenablestate}" />
if button.content
set binding
works fine , have different problem.
update 2 >>>
as @charleh mentioned, need make sure have notified inotifypropertychanged
interface of change of property value:
notifyofpropertychange(() => buttonenablestate);
Comments
Post a Comment