Align buttons side by side
c#, xamarin
Solution
I got it to work with some StackLayout inception like this:
MainPage = new ContentPage
{
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Spacing = 40,
Children = {
new Label {
XAlign = TextAlignment.Center,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
Text = "Hey there here is where you spent your time!"
},
new Label()
{
XAlign = TextAlignment.Center,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
Text = "Time spent near beacon A: "
},
new Label()
{
XAlign = TextAlignment.Center,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
Text = "Time spent near beacon B: "
},
new StackLayout()
{
HorizontalOptions = LayoutOptions.Center,
Orientation = StackOrientation.Horizontal,
Children = {
new Button()
{
VerticalOptions = LayoutOptions.Start,
HorizontalOptions = LayoutOptions.Start,
Text = "Start Tracking"
},
new Button()
{
VerticalOptions = LayoutOptions.Start,
HorizontalOptions = LayoutOptions.Start,
Text = "Stop Tracking"
}
}
}
}
}
};
Problem
I am trying to align the last 2 buttons next to each other (side-by-side), this was a lot easier in XAML, how can I achieve this using code approach? ``` MainPage = new ContentPage { Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Spacing = 40, Children = { new Label { XAlign = TextAlignment.Center, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand, Text = "Hey there here is where you spent your time!" }, new Label() { XAlign = TextAlignment.Center, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand, Text = "Time spent near beacon A: " }, new Label() { XAlign = TextAlignment.Center, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand, Text = "Time spent near beacon B: " }, new Button() { VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Start, Text = "Start Tracking" }, new Button() { VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Start, Text = "Stop Tracking" } } } }; ``` Thanks for any input.