Skip to content

Instantly share code, notes, and snippets.

@UdaraAlwis
Last active September 26, 2019 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UdaraAlwis/dcdfa8b785eebc81da053ffaa8c22d3e to your computer and use it in GitHub Desktop.
Save UdaraAlwis/dcdfa8b785eebc81da053ffaa8c22d3e to your computer and use it in GitHub Desktop.
Fill in the blanks question form in Xamarin Forms
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace App2
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
static Color[] colors = { Color.Red, Color.Magenta, Color.Blue,
Color.Cyan, Color.Green, Color.Yellow };
static string[] digitsText = { "", "One", "Two", "Three aksduiwe", "Four", "Five",
"Six", "Seven rasdkj", "Eight", "Nine", "Ten",
"Eleven", "Twelve", "Thirteen", "Fourteen ajshd",
"Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
static string[] decadeText = { "", "", "as Twenty", "Thirty aywue", "Forty", "Fiftyajksd",
"Sixty", "Seventy ajsk asid", "Eighty", "Ninety" };
public MainPage()
{
InitializeComponent();
numberStepper.Value = 30;
OnNumberStepperValueChanged(flexLayout, new ValueChangedEventArgs(0, numberStepper.Value));
}
void OnNumberStepperValueChanged(object sender, ValueChangedEventArgs args)
{
int count = (int)args.NewValue;
while (flexLayout.Children.Count > count)
{
flexLayout.Children.RemoveAt(flexLayout.Children.Count - 1);
}
while (flexLayout.Children.Count < count)
{
int number = flexLayout.Children.Count + 1;
string text = "";
if (number < 20)
{
text = digitsText[number];
}
else
{
text = decadeText[number / 10] +
(number % 10 == 0 ? "" : "-") +
digitsText[number % 10];
}
Label label = new Label
{
Text = text,
FontSize = 16,
Margin = new Thickness(5, 5, 5, 5),
VerticalOptions = LayoutOptions.Center,
VerticalTextAlignment = TextAlignment.Center,
TextColor = Color.Black,
BackgroundColor = Color.White
};
Entry entry = new Entry
{
Placeholder = text,
FontSize = 16,
BackgroundColor = Color.White
};
Random rand = new Random();
int x = rand.Next(2);
if (x == 0)
{
flexLayout.Children.Add(entry);
}
else
{
flexLayout.Children.Add(label);
}
}
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="App2.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
ios:Page.UseSafeArea="true"
mc:Ignorable="d">
<!-- Place new controls here -->
<StackLayout Padding="20,20,20,20">
<Stepper
x:Name="numberStepper"
Increment="1"
Maximum="99"
Minimum="0"
ValueChanged="OnNumberStepperValueChanged"
Value="3" />
<ScrollView>
<!-- FlexLayout -->
<ScrollView Grid.Row="1">
<FlexLayout
x:Name="flexLayout"
AlignContent="Start"
AlignItems="Center"
BackgroundColor="White"
Direction="Row"
JustifyContent="Start"
Wrap="Wrap">
<Label FontSize="16" Text="Warning this " />
<Label FontSize="16" Text="asdasd asd this " />
<Label FontSize="16" Text="Marin " />
<Label FontSize="16" Text="Warning this " />
<Label FontSize="16" Text="asdasd s this " />
<Label FontSize="16" Text="as this " />
<Label FontSize="16" Text="wefas asd asdas this " />
</FlexLayout>
</ScrollView>
</ScrollView>
</StackLayout>
</ContentPage>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment