mvvm - Windows Phone TextBox raise command RaiseCanExecuteChanged on TextChanged? -


I have a text box and a button that is bound to a property in my visual model as

  & lt; Text box text = "{binding user name, mode = double}" /> & Lt; Button content = "sign in" command = "{binding login prompt}" />  

My username property:

  private string user name; Get public string username {this.userName; } Set {SetProperty (referee username, value); (DelegateCommand) (this.LoginCommand)) RaiseCanExecuteChanged () .; }}  

login command:

  login comand = new representative comand (user_ogin, can_ogin);  

and Can_Login Method:

  private bool Kan_ogin (Object arg) {if (! String.IsNullOrEmpty (UserName)) Back true; return false; }  

My problem is that the login button is always enabled until the user's name text box is empty and lost focus .

Do I want to enable the button to do this, when the user types text boxes instantly without focusing some text in the text box.

Is there an alternative solution for this?

Try playing with property of UpdateSourceTrigger binding. The text box has this set by default on lostfocus event, so in this situation it is called RaiseCanExecuteChanged . In WPF, we can set it to PropertyChanged LostFocus event:

   without waiting for the text box   Textbox = "" {binding username, mode = Dowa, Apdetsorstrigr = property change} "/ & gt;  

Unfortunately, property turned Rililait is not available for the call windows. clear and TextChanged manually on raised event using binding UpdateSource Event The requirement is:

  & lt; Textbox text = "{Binding user name, mode change = Dowa, Apdetsorstrigr = explanation}" text = "Ontakst Chenjed" / & gt; // code back Private OnTextChanged zero (object sender, TextChangedEventArgs e) from as {textbox textbox = text box, binding Akspereshn binding Akspraft = text box. Getboiding Akspsn (text box. Patproparti); // manually UpdateSource bindingExpr.UpdateSource ( ) Call; }  

Note that the right code-behind in case (Mvivim of Pont-of-view), because it just acts relating to certain UI / binding, not work-related data Does. / P>

Reference:


Comments