我想明确的进入文字从我的视图模型,它被绑定在那里。 在下面这段代码我尝试过通过使用RelayCommand,但是它不工作。
我想要完成的任务:当击按钮 AddQuestionToQuiz
,职能是执行的命令使用的按钮。 功能 OnCreateQuizClick()
位于我的视图模型,是triggerd和这种功能的需要清楚我的条文,我不会的时刻。
我还试着用一个常规的命令,而不是使用RelayCommand,但是也在这里不想要的工作。
编辑:下码工作的微得到了更新 代码被用于明确的条文时,点击按钮从你的视图模型,实施举的接口
.xaml码
<Button x:Name="AddQuestionToQuiz" WidthRequest="200" Command="{Binding CreateQuizCommand}" Style="{StaticResource ButtonStyle}" Text="Add question to quiz"></Button>
视图模型的代码
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 = "";
}
}