Vorrei cancellare la voce di testo dal mio ViewModel che è legato lì. Nel codice riportato di seguito ho provato utilizzando un RelayCommand, ma non funziona.
Quello che voglio realizzare: cliccando il pulsante denominato AddQuestionToQuiz
una funzione viene eseguita utilizzando il Comando sul pulsante. La funzione OnCreateQuizClick()
situato a mio ViewModel, è triggerd e questa funzione ha bisogno di pulire la mia voce testo, che non riesco per il momento.
Ho provato anche ad utilizzare un normale Comando invece di utilizzare un RelayCommand, ma anche qui non ha voglia di lavorare.
EDIT: SOTTO IL CODICE FUNZIONA BENE - È STATO AGGIORNATO IL Il codice è utilizzato per cancellare la voce di testo quando si fa clic su un pulsante da ViewModel, l'implementazione di Interfaccia INotifyPropertyChanged
.xaml - codice
<Button x:Name="AddQuestionToQuiz" WidthRequest="200" Command="{Binding CreateQuizCommand}" Style="{StaticResource ButtonStyle}" Text="Add question to quiz"></Button>
ViewModel - codice
internal class CreateQuizPageViewModel : INotifyPropertyChanged
{
// Quiz Name Input
public String QuizNameInput { get; set; }
private String quizQuestionInput = "";
public String QuizQuestionInput
{
get { return quizQuestionInput; }
set { quizQuestionInput = value; OnPropertyChanged(); }
}
public RelayCommand CreateQuizCommand { get; set; }
public CreateQuizPageViewModel()
{
CreateQuizCommand = new RelayCommand(OnCreateQuizClick);
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void OnCreateQuizClick()
{
QuizQuestionInput = "";
}
}