Aș dori să clarific intrare text din ViewModel care se ajunge acolo. În codul de mai jos am încercat prin utilizarea unui RelayCommand, dar nu merge.
Ceea ce vreau să realizeze: atunci Când faceți clic pe butonul numit AddQuestionToQuiz
o funcție este executată utilizând Comanda pe buton. Funcția OnCreateQuizClick()
situat în ViewModel, este declanșat și această funcție are nevoie pentru a-mi limpezi de text de intrare, care nu ajunge pentru moment.
Am încercat de asemenea să utilizeze în mod regulat de Comandă în loc de a folosi un RelayCommand, dar, de asemenea, aici nu vreau să lucrez.
EDIT: SUB COD FUNCȚIONEAZĂ BINE - AM ACTUALIZAT Codul este utilizat pentru a șterge intrare text atunci când faceți clic pe un buton de pe ViewModel, de punere în aplicare INotifyPropertyChanged Interfață
.xaml - cod
<Button x:Name="AddQuestionToQuiz" WidthRequest="200" Command="{Binding CreateQuizCommand}" Style="{StaticResource ButtonStyle}" Text="Add question to quiz"></Button>
ViewModel - cod
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 = "";
}
}