Claro de entrada de texto de ViewModel utilizando RelayCommand

0

Pregunta

Me gustaría aclarar de entrada de texto desde mi ViewModel que está encuadernada de allí. En el siguiente código lo he probado mediante el uso de un RelayCommand, pero no funciona.

Lo que quiero lograr: Al hacer clic en el botón de llamada AddQuestionToQuizuna función se ejecuta mediante el uso de Comandos en el botón. La función OnCreateQuizClick(), que se encuentra en mi ViewModel, es triggerd y esta función es necesario borrar mi entrada de texto, que no tengo por el momento.

También traté de usar un Comando en lugar de utilizar un RelayCommand, pero también aquí no quieren trabajar.

EDIT: POR DEBAJO DE CÓDIGO FUNCIONA BIEN - LA TENGO ACTUALIZADA El código se utiliza para borrar la entrada de texto al hacer clic en un botón de su ViewModel, la implementación de Interfaz INotifyPropertyChanged

.xaml código

<Button x:Name="AddQuestionToQuiz" WidthRequest="200" Command="{Binding CreateQuizCommand}" Style="{StaticResource ButtonStyle}" Text="Add question to quiz"></Button>

ViewModel - código

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 = "";
    }
}
1

Mejor respuesta

0

EDIT: ACTUALIZADO VIEWMODEL

.xaml código

<Button x:Name="AddQuestionToQuiz" WidthRequest="200" Command="{Binding CreateQuizCommand}" Style="{StaticResource ButtonStyle}" Text="Add question to quiz"></Button>

ViewModel - código

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 = "";
    }
}
2021-11-24 08:58:05

En otros idiomas

Esta página está en otros idiomas

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Slovenský
..................................................................................................................