c# - CanExecute in DelegateCommand and expression declaration doesn't work -


my question straightforward. why works:

public delegatecommand logincommand { get; }  func<bool> canexecutelogin = () => !stringservice.isnullorempty(_entries.logintext, _entries.passwordtext); logincommand = new delegatecommand(onlogintapped, canexecutelogin); 

but doesn't:

public delegatecommand logincommand => new delegatecommand(onlogintapped,             () => !stringservice.isnullorempty(_entries.logintext, _entries.passwordtext)); 

i check so:

 public string loginentrytext         {             { return _entries.logintext; }             set             {                 _entries.logintext = value;                 logincommand?.raisecanexecutechanged();             }         } 

doesn't work, mean func never executes after initialization.

question not entirely clear me, suspect reason follows.

this

public delegatecommand logincommand => new delegatecommand(...) 

is equivalent this

public delegatecommand logincommand { {return new delegatecommand(...)}} 

so every time access logincommand property - returns new delegatecommand instance. means raisecanexecutechanged on fresh instance of command, , code called property before , can react change use own instances.

that's unlike first scenario there 1 instance of delegatecommand used everyone.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -