ฉันอยากจะมีทรัพย์สินขอ ViewModel นั่นมันเกี่ยวข้องกับของฉัน StackLayout. ฉันพยายามทั้งหมดนี่คนเดียถูกเชื่อมโยงของฉัน StackLyout ที่ ViewModel.
ตอนที่ฉันคลิกบนปุ่มนี้ผังแป้นพิมพ์ควรจะต้องทำเรื่องไร้ตัวตน
ตอนที่ฉันทำอย่างนี้กับรหัสทางด้านล่าของฉันโปรแกรมทำงานขัดข้องกับ NulReferenceObject:อ้างอิงถึงวัตถุงไม่ถูกตั้งค่าให้เป็นตัวอย่างของวัตถุชิ้นหนึ่ง ที่ StackLayout ว่าฉันพูดถึงเรื่องเป็นครั้งแรกในรหัสทางด้านล่างนี้
<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>
ViewModel
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;
}
}