c# - Why is a button enabled if the Command binding resolves to null? -
ok, xaml quite simple , uses mvvm bind icommand somecommand { get; }
property on view model:
<button command="{binding path=somecommand}">something</button>
if somecommand
returns null
, button enabled. (nothing canexecute(object param)
method on icommand
, because there no instance call method on)
and question: why button enabled? how work around?
if press "enabled" button, nothing called. ugly button looks enabled.
it enabled because that's default state. disabling automatically arbitrary measure gives rise other problems.
if want have button without associated command disabled, bind isenabled
property somecommand
using appropriate converter, e.g.:
[valueconversion(typeof(object), typeof(bool))] public class nulltobooleanconverter : ivalueconverter { public object convert(object value, type targettype, object parameter, cultureinfo culture) { return value !== null; } public object convertback(object value, type targettype, object parameter, cultureinfo culture) { throw new notsupportedexception(); } }
Comments
Post a Comment