-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainPage.xaml.cs
67 lines (59 loc) · 1.95 KB
/
MainPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace Geometric
{
// 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
{
public MainPage()
{
// Configuration
var blockSize = 50;
var colors = new List<Color>()
{
Color.FromHex("#E8E9B7"),
Color.FromHex("#B0BAA4"),
Color.FromHex("#7A8992"),
Color.FromHex("#6D657E")
};
InitializeComponent();
// Get Display dimensions using Xamarin.Essentials
var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
var screenWidth = mainDisplayInfo.Width;
var screenHeight = mainDisplayInfo.Height;
// Build the UI
var xPos = 0;
var yPos = 0;
while (yPos < screenHeight)
{
var rowColors = colors.GetRange(0, colors.Count);
while (xPos < screenWidth)
{
rowColors = Reorder(rowColors);
backgroundLayout.Children.Add(new Block(new Thickness(xPos, yPos), blockSize,
rowColors[0], rowColors[1], rowColors[2], rowColors[3]));
xPos += blockSize;
}
colors = Reorder(colors);
xPos = 0;
yPos += blockSize;
}
}
// Reorder list by moving the first item to the back
public List<Color> Reorder(List<Color> list)
{
var first = list.First();
list.RemoveAt(0);
list.Add(first);
return list;
}
}
}