मैं होगा की तरह है करने के लिए एक संपत्ति में 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;
}
}