Skip to content

Instantly share code, notes, and snippets.

@luismts
Last active May 8, 2020 16:04
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 luismts/bedb5483d79215d7f818774a6f473518 to your computer and use it in GitHub Desktop.
Save luismts/bedb5483d79215d7f818774a6f473518 to your computer and use it in GitHub Desktop.
A comparison between classic C#, C# markup, and XAML for creating UI
var grid = new Grid();
var label = new Label { Text = "Code:" };
grid.Children.Add(label, 0, 1);
var entry = new Entry
{
Placeholder = "Enter number",
Keyboard = Keyboard.Numeric,
BackgroundColor = Color.AliceBlue,
TextColor = Color.Black,
FontSize = 15,
HeightRequest = 44,
Margin = 20
};
grid.Children.Add(entry, 0, 2);
Grid.SetColumnSpan(entry, 2);
entry.SetBinding(Entry.TextProperty, new Binding("RegistrationCode"));
Content = grid;
Content = new Grid {
Children = {
new Label { Text = "Code:" }.Row(1),
new Entry {
Placeholder = "Enter number",
Keyboard = Keyboard.Numeric,
BackgroundColor = Color.AliceBlue,
TextColor = Color.Black
}
.Font(15)
.Row(2)
.ColumnSpan(2)
.Margin(20)
.Height(44)
.Bind("RegistrationCode")
}};
Content = new Grid
{
Children = {
new Label { Text = "Code:" }
.Row(1),
new Entry {
Placeholder = "Enter number",
Keyboard = Keyboard.Numeric,
BackgroundColor = Color.AliceBlue,
TextColor = Color.Black
}
.Font(15)
.Row(2)
.ColumnSpan(2)
.Margin(20)
.Height(44)
.Bind("RegistrationCode")
}
};
Content = new Grid {
Children = {
new Label { Text = "Code:" }.Row(1),
new Entry {
Placeholder = "Enter number",
Keyboard = Keyboard.Numeric,
BackgroundColor = Color.AliceBlue,
TextColor = Color.Black,
FontSize = 15,
HeightRequest = 44,
Margin = 20
}
.Row(2)
.ColumnSpan(2)
.Bind("RegistrationCode")
}};
<ContentPage.Content>
<Grid>
<Label Grid.Row="1" Text="Code:" />
<Entry
Grid.Row="1"
Grid.ColumnSpan="2"
Margin="20"
BackgroundColor="AliceBlue"
FontSize="15"
HeightRequest="44"
Keyboard="Numeric"
Placeholder="Enter number"
Text="{Binding RegistrationCode}"
TextColor="Black" />
</Grid>
</ContentPage.Content>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment