Step 1
If not already, follow Setup and Start on how to Install and get Started with Visual Studio 2017 or in Windows 10 choose Start, and then from the Start Menu locate and select Visual Studio 2017.
Step 2
Once Visual Studio Community 2017 has started, from the Menu choose File, then New then Project…
Step 3
From New Project choose Visual C# from Installed, Templates then choose Cross Platform App (Xamarin) and then type in a Name and select a Location and then select Ok to create the Project
Step 4
Then in New Cross Platform App you need to select the Blank App Template then from UI Technology select Xamarin.Forms and in Code Sharing Strategy select Shared Project and then select Ok to continue
Step 5
The Xamarin Mac Agent will be displayed allowing connection to an Apple Mac but this can be dismissed with Close if running solely on Windows 10
Step 6
Then in New Universal Windows Project you need to select the Target Version to be Windows 10 Creators Update (10.0; Build 15063) and the Minimum Version to Windows 10 Creators Update (10.0; Build 15063) and then select Ok
Step 7
From the Menu choose Project, then Add New Item…
From the Add New Item choose Visual C# from Installed then choose Code then select Code File and then in the Name as Stacked.cs and then select Add to add the file to the Project
Step 9
Then in the Code View for Stacked.cs the following should be entered:
using System; using System.Collections.Generic; using System.Linq; using Xamarin.Forms; namespace StackedControl { public class Stacked : Grid { private List<Color> _palette = new List<Color>(); private List<double> _items = new List<double>(); private List<double> Percentages() { List<double> results = new List<double>(); double total = _items.Sum(); foreach (double item in _items) { results.Add((item / total) * 100); } return results.OrderBy(o => o).ToList(); } private BoxView GetBox(Color colour, int column) { BoxView box = new BoxView() { InputTransparent = true, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, BackgroundColor = colour }; box.SetValue(Grid.ColumnProperty, column); return box; } private void Layout() { this.RowSpacing = 0; this.ColumnSpacing = 0; List<double> percentages = Percentages(); this.ColumnDefinitions.Clear(); for (int index = 0; index < percentages.Count(); index++) { double percentage = percentages[index]; ColumnDefinition column = new ColumnDefinition() { Width = new GridLength(percentage, GridUnitType.Star) }; this.ColumnDefinitions.Add(column); Color colour = (index < _palette.Count()) ? _palette[index] : Color.Black; Children.Add(GetBox(colour, index)); } } public List<Color> Palette { get { return _palette; } set { _palette = value; } } public List<double> Items { get { return _items; } set { _items = value; Layout(); } } public void Fibonacci(params Color[] colours) { Palette = colours.ToList(); Func<int, int> fibonacci = null; fibonacci = value => value > 1 ? fibonacci(value - 1) + fibonacci(value - 2) : value; Items = Enumerable.Range(0, Palette.Count()) .Select(fibonacci).Select(s => (double)s).ToList(); } } }
Step 10
In the Solution Explorer select MainPage.xaml from the Shared Project
Step 11
From the Menu choose View and then Open
Step 12
The XAML View will be displayed, and in this remove the Label then between the ContentPage and /ContentPage elements, enter the following XAML:
<Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <local:Stacked Grid.Row="0" x:Name="Display" Margin="50"/> <Grid Grid.Row="1" Margin="10"> <Button Text="Show" HorizontalOptions="Center" WidthRequest="100" Clicked="Show_Clicked"/> </Grid> </Grid>
It should appear as such:
Step 13
In the Solution Explorer select the Expand arrow next to MainPage.xaml to open MainPage.cs, then select this from the Shared Project
Step 14
From the Menu choose View and then Open
Step 15
Once in the Code View, below the public MainPage() { … } the following Code should be entered:
private void Show_Clicked(object sender, EventArgs e) { Display.Fibonacci( Color.Black, Color.Gray, Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Cyan, Color.Blue, Color.Magenta, Color.Purple); }
It should then appear as such:
Step 16
That completes the application, so from the Menu choose Build and then Build Solution
Step 17
Then from the Menu choose Debug then Start Debugging to run the Application in the Android Emulator
Step 18
Once started the Application should then appear in the Android Emulator
Step 19
After the Application has started running you can then select Show which should display a Stacked Chart based on the Palette in a Fibonacci sequence
Step 20
To Exit the Application select Stop in Visual Studio
Step 21
Another option is to run as a Universal Windows Application. From Solution Explorer select the Project ending with .UWP (Universal Windows), then from the Menu choose Project then Set as StartUp Project
Step 22
Then again from the Menu choose Build and then select the Deploy option ending with .UWP
Step 23
Then once again from the Menu choose Debug then Start Debugging to run the Application in Windows 10
Step 24
Once started the Application should then appear
Step 25
After the Application has started running you can then select Show which should display a Stacked Chart based on the Palette in a Fibonacci sequence
Step 26
To Exit the Application select Stop in Visual Studio
Step 27
Also if you have Mac with the Xamarin tools installed and have enabled and connected to the Xamarin Mac Agent. From Solution Explorer select the Project ending with .iOS, then from the Menu choose Project then Set as StartUp Project
Step 28
Then once again from the Menu choose Debug then Start Debugging to run the Application for iOS
Step 29
Once started the Application should then appear
Step 30
After the Application has started running you can then select Show which should display a Stacked Chart based on the Palette in a Fibonacci sequence
Step 31
To Exit the Application select Stop in Visual Studio
Thanks for Julia Boichentsova for helping with iOS screenshots