I want to disable the send button if any of the three entries is empty, but how that can be achieved in an MVVM fashion?
I thought of the CanExecute delegate, but how can I fire it whenever the TextChanged fired?
Also if I opt in the behaviors, how can I communicate with other controls like button if I'm using Behavior<Entry>
This is the view:
<ContentPage.Content>
<AbsoluteLayout>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="56"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="10"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Label Text="Contact Us" FontSize="Medium" Grid.ColumnSpan="3"/>
<Entry Text="{Binding ContactData.message_name}" x:Name="subject" Grid.Row="2" Grid.Column="1" Placeholder="Subject"/>
<Entry Keyboard="Email" Text="{Binding ContactData.receiver_email}" x:Name="email" Grid.Row="3" Grid.Column="1" Placeholder="Email"/>
<Editor Text="{Binding ContactData.message_subject}" x:Name="body" Grid.Row="4" Grid.Column="1" />
<Button Grid.Row="5" Grid.Column="1" Command="{Binding ContactFormSent}" Text="Send"/>
</Grid>
</AbsoluteLayout>
</ContentPage.Content>
in the ViewModel:
public ContactViewModel()
{
ContactFormSent = new RelayCommand(SendContactInfo);
ContactData = new ContactModel();
}
private bool CanSend() //this only get called when the view model is constructed
{
return !(string.IsNullOrWhiteSpace(ContactData.receiver_email) && string.IsNullOrWhiteSpace(ContactData.message_subject) &&
string.IsNullOrWhiteSpace(ContactData.message_name));
}
In the Behavior option, I wan it to be used with both Entry and Editor, so is my way to go is the Behavior class, not the generic version? if so, then how can I implement it?