I'm still learning Xamarin Forms and C# in general. So in my MainPage.xaml i have this:
<StackLayout>
<Button Text="bttn1" Clicked="Button_Clicked"/>
<Button Text="bttn2" Clicked="Button_Clicked_1"/>
<ContentView x:Name="DisplayCustomContentView">
</ContentView>
</StackLayout>
and two ContentViews:
View 1:
public class View1 : ContentView
{
public View1 ()
{
Content = new StackLayout {
Children = {
new Label { Text = "View 1" },
new Entry {Placeholder = "entry1 View 1"},
new Entry {Placeholder = "entry2 View 1"}
}
};
}
}
View 2:
public class View2 : ContentView
{
public View2 ()
{
Content = new StackLayout {
Children = {
new Label { Text = "View 2" },
new Entry {Placeholder = "entry2 View 1"},
new Entry {Placeholder = "entry2 View 2"}
}
};
}
}
So I want to swap between the views when I click on the buttons. I have tried this:
private void Button_Clicked(object sender, EventArgs e)
{
DisplayCustomContentView = new View1();
}
And how can i get the values from the Entry fields?
I'm mostly certain that I'm doing not the right way. And I could use all the help I can get!