Hello evreryone
Just a quick question
I have my view
<ContentPage.BindingContext>
<vm:RegisterViewModel />
</ContentPage.BindingContext>
<ScrollView>
<StackLayout Spacing="20">
<Image Style="{StaticResource ImageStyle}"
Margin="0,20,0,0" />
<ActivityIndicator IsRunning="{Binding IsBusy}"
Color="#28A586" />
<Grid Margin="10,0,20,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Image Source="Usuario.png" />
<Entry Placeholder="Useario"
Text="{Binding Username}"
Grid.Column="1"
Style="{StaticResource Key=EntryStyle}" />
<Image Source="Clave.png"
Grid.Row="1" />
<Label Text="Debe tener al menos 8 caracteres y un carácter especial"
Grid.Column="1"
TextColor="White"
Margin="0,-7,0,0"
Grid.Row="2"
FontSize="11" />
<Entry Placeholder="Contraseña"
Text="{Binding Password}"
IsPassword="True"
Grid.Column="1"
Grid.Row="1"
Style="{StaticResource EntryStyle}" />
<Image Source="Clave.png"
Grid.Row="3" />
<Entry Placeholder="Confirmar contraseña"
Text="{Binding ConfrimPassword}"
Style="{StaticResource EntryStyle}"
IsPassword="True"
Grid.Column="1"
Grid.Row="3" />
<Image Source="Email.png"
Grid.Row="4" />
<Entry Placeholder="Correo Electrónico"
Keyboard="Email"
Text="{Binding Email}"
Style="{StaticResource EntryStyle}"
Grid.Column="1"
Grid.Row="4" />
</Grid>
<Button Text="Registrame"
Command="{Binding RegisterCommand}"
Style="{StaticResource Key=YellowButtons}"
IsEnabled="{Binding IsEnable}"
Margin="0,20,0,0" />
<Grid Margin="10,10,10,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
</Grid.ColumnDefinitions>
<StackLayout Orientation="Horizontal">
<Button Text="Registro con facebook"
FontSize="8"
TextColor="White"
Command="{Binding FacebookCommand}"
ContentLayout="Left,20"
Image="Facebook.png"
HorizontalOptions="Start"
BackgroundColor="Transparent" />
</StackLayout>
<StackLayout Grid.Column="2"
Orientation="Horizontal">
<Button Text="Registro con Gmail"
FontSize="8"
Command="{Binding GmailCommand}"
ContentLayout="Left,20"
Image="Gmail.png"
TextColor="White"
BackgroundColor="Transparent"
HorizontalOptions="Start" />
</StackLayout>
</Grid>
</StackLayout>
</ScrollView>
and my view model
class RegisterViewModel : BaseViewModel {
public ICommand RegisterCommand { get; set; }
public ICommand FacebookCommand { get; set; }
public ICommand GmailCommand { get; set; }
public RegisterViewModel() {
IsEnable = false;
FacebookCommand = new Command(() => {
Application.Current.MainPage.DisplayAlert("", "Calling facebook", "OK");
});
GmailCommand = new Command(() => {
Application.Current.MainPage.DisplayAlert("", "Calling Gmail", "OK");
});
RegisterCommand = new Command(async () => {
IsBusy = true;
JObject data = new JObject {
{ "username", Username.ToLower() },
{ "password", Password.ToLower() },
{ "email", Email.ToLower() }
};
var obj = await NetworkHelpper.SendData(Constants.REGISTER, data);
string result = obj.Content.ReadAsStringAsync().Result;
if (obj.IsSuccessStatusCode) {
IsBusy = false;
// Application.Current.MainPage.Navigation.PushAsync(new LoginScreen(), true);
} else {
IsBusy = false;
await Application.Current.MainPage.DisplayAlert("Error", result, "ok");
}
});
}
private string _Username;
public string Username {
get { return _Username; }
set {
_Username = value;
RaisePropertyChanged();
if (Validator()) {
IsEnable = false;
} else {
IsEnable = true;
}
}
}
private string _ConfrimPassword;
public string ConfrimPassword {
get { return _ConfrimPassword; }
set {
if (_ConfrimPassword != value) {
_ConfrimPassword = value;
RaisePropertyChanged();
if (Validator()) {
IsEnable = false;
} else {
IsEnable = true;
}
}
}
}
private string _Password;
public string Password {
get { return _Password; }
set {
if (_Password != value) {
_Password = value;
RaisePropertyChanged();
if (Validator()) {
IsEnable = false;
} else {
IsEnable = true;
}
}
}
}
private string _Email;
public string Email {
get { return _Email; }
set {
if (_Email != value) {
_Email = value;
RaisePropertyChanged();
if (Validator()) {
IsEnable = false;
} else {
IsEnable = true;
}
}
}
}
private bool Validator() {
return string.IsNullOrEmpty(_Username)
|| string.IsNullOrEmpty(_Password)
|| string.IsNullOrEmpty(_ConfrimPassword)
|| string.IsNullOrEmpty(_Email)
|| _ConfrimPassword != _Password;
}
private bool _IsEnable;
public bool IsEnable {
get { return _IsEnable; }
set {
if (_IsEnable != value) {
_IsEnable = value;
RaisePropertyChanged();
}
}
}
private bool _IsBusy;
public bool IsBusy {
get { return _IsBusy; }
set {
if (_IsBusy != value) {
_IsBusy = value;
RaisePropertyChanged();
}
}
}
}
}
For some weird reason the button is not getting disable or enable or anything, but the buttons that the commands are bind to facebook command and gmail command are working perfectly. Any thought?