Skip to content

Instantly share code, notes, and snippets.

@bulentsiyah
Created November 3, 2017 23:01
Show Gist options
  • Save bulentsiyah/c0eb44a6b074ada29b479f7311b8cfef to your computer and use it in GitHub Desktop.
Save bulentsiyah/c0eb44a6b074ada29b479f7311b8cfef to your computer and use it in GitHub Desktop.
Xamarin Forms Example: Scrolling The Stack
App.cs
MainPage = new NavigationPage(new Main());
Main.cs
public class Main : ContentPage
{
public Main()
{
var colors = new[]
{
new { value = Color.White, name = "White" },
new { value = Color.Silver, name = "Silver" },
new { value = Color.Gray, name = "Gray" },
new { value = Color.Black, name = "Black" },
new { value = Color.Red, name = "Red" },
new { value = Color.Maroon, name = "Maroon" },
new { value = Color.Yellow, name = "Yellow" },
new { value = Color.Olive, name = "Olive" },
new { value = Color.Lime, name = "Lime" },
new { value = Color.Green, name = "Green" },
new { value = Color.Aqua, name = "Aqua" },
new { value = Color.Teal, name = "Teal" },
new { value = Color.Blue, name = "Blue" },
new { value = Color.Navy, name = "Navy" },
new { value = Color.Pink, name = "Pink" },
new { value = Color.Fuchsia, name = "Fuchsia" },
new { value = Color.Purple, name = "Purple" }
};
StackLayout stackLayout = new StackLayout
{
Orientation = StackOrientation.Vertical,
Spacing = 10,
};
foreach (var color in colors)
{
stackLayout.Children.Add(
new Label
{
Text = color.name,
TextColor = color.value,
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label))
});
}
ScrollView scrollView = new ScrollView
{
Content = stackLayout,
};
Frame frame = new Frame
{
OutlineColor = Color.Accent,
BackgroundColor = Color.White,
Content = new Label
{
Text = "I've been framed!",
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
FontAttributes = FontAttributes.Italic,
TextColor = Color.Blue
}
};
BoxView boxViewnew = new BoxView
{
Color = Color.Navy,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
WidthRequest = 200,
HeightRequest = 100
};
Content = new StackLayout()
{
Orientation = StackOrientation.Vertical,
Spacing = 20,
Children = { frame, boxViewnew, scrollView }
};
Padding = new Thickness(5, Device.OnPlatform(10, 5, 5), 5, 5);
Title = "Scrolling The Stack";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment