Viewmodel'imde stacklayout'uma bağlı bir özelliğe sahip olmak istiyorum. Bunu stacklyout'umu Viewmodel'e bağlayarak denedim.
Bir düğmeye tıkladığımda, bu düzen görünmez hale getirilmelidir.
Bunu aşağıdaki kodla yaptığımda, programım bir nesnenin örneğine ayarlanmamış bir NulReferenceObject: Object Referansı ile çöküyor. Bahsettiğim StackLayout, aşağıdaki koddaki ilk koddur.
<FlexLayout>
<StackLayout BindableLayout.ItemTemplate="{Binding CreateQuizPageQuizNameSL}"> // This StackLayout should be bind to the ViewModel
<Label Text="Create New Quiz" />
<StackLayout >
<Entry Text="{Binding QuizNameInput}" Placeholder="Enter quiz name"/>
</StackLayout>
</StackLayout>
<Button Command="{Binding SubmitCreateQuizCommand}" Text="Create my quiz now!"></Button>
</FlexLayout>
Görünüm Modeli
internal class CreateQuizPageViewModel
{
// Quiz Name Input
public String QuizNameInput { get; set; }
// Command submit creating a quiz
public Command SubmitCreateQuizCommand { get; set; }
public StackLayout CreateQuizPageQuizNameSL { get; set; } = new StackLayout();
public CreateQuizPageViewModel()
{
// Declaring a new command, giving the OnSubmitCreateNewQuizClick to the delegate
SubmitCreateQuizCommand = new Command(OnSubmitCreateNewQuizClick);
}
// When a user submit the creation of new quiz
public void OnSubmitCreateNewQuizClick()
{
CreateQuizPageQuizNameSL.IsVisible = false;
}
}