Hi!
Sorry - another question from a relative newbie to mobile development and Xamarin.
I am experimenting with creating a custom popup keypad, and I am working with an example from https: //docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/grid* (slightly modified). As the ultimate keypad will be dynamic in layout/content, I am using the code-behind cs file for layout (yes, I know this is not recommended...but I am unsure how to do dynamic layout within xaml).
Anyway, I am having difficulty with the (standard) rendering of the Grid. When I use ColumnSpacing = 1, the spacing between cells in columns 1 & 2 (except for row 5, following a column span) does not appear, and none of the spacing between columns 2 & 3 shows, as seen in this screenshot (using the VS Android emulator):
![]()
I cannot understand why, apparently, the spacing shown there is one less than specified. To prove this, I changed ColumnSpacing (and RowSpacing) to 2, and (as you can see) the spacing now shows, but is narrower than the other spacings:
![]()
I have searched online to no avail. All I can find are questions related to removing the column and row spacing.
Here is the class definition (again, as modified from the referenced sample):
public partial class CalculatorGridCode : Grid
{
public CalculatorGridCode()
{
// Title = "Calculator - C#";
BackgroundColor = Color.FromHex("#404040");
RowSpacing = 1; ColumnSpacing = 1;
var plainButton = new Style(typeof(Button))
{
Setters = {
new Setter { Property = Button.BackgroundColorProperty, Value = Color.FromHex ("#eee") },
new Setter { Property = Button.TextColorProperty, Value = Color.Black },
new Setter { Property = Button.CornerRadiusProperty, Value = 0 },
new Setter { Property = Button.FontSizeProperty, Value = 40 }
}
};
var darkerButton = new Style(typeof(Button))
{
Setters = {
new Setter { Property = Button.BackgroundColorProperty, Value = Color.FromHex ("#ddd") },
new Setter { Property = Button.TextColorProperty, Value = Color.Black },
new Setter { Property = Button.CornerRadiusProperty, Value = 0 },
new Setter { Property = Button.FontSizeProperty, Value = 40 }
}
};
var orangeButton = new Style(typeof(Button))
{
Setters = {
new Setter { Property = Button.BackgroundColorProperty, Value = Color.FromHex ("#E8AD00") },
new Setter { Property = Button.TextColorProperty, Value = Color.White },
new Setter { Property = Button.CornerRadiusProperty, Value = 0 },
new Setter { Property = Button.FontSizeProperty, Value = 40 }
}
};
RowDefinitions.Add(new RowDefinition { Height = new GridLength(150) });
RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
var label = new Label
{
Text = "0",
HorizontalTextAlignment = TextAlignment.End,
VerticalTextAlignment = TextAlignment.End,
TextColor = Color.White,
FontSize = 60
};
Children.Add(label, 0, 0);
Grid.SetColumnSpan(label, 4);
Children.Add(new Button { Text = "C", Style = darkerButton }, 0, 1);
Children.Add(new Button { Text = "+/-", Style = darkerButton }, 1, 1);
Children.Add(new Button { Text = "%", Style = darkerButton }, 2, 1);
Children.Add(new Button { Text = "div", Style = orangeButton }, 3, 1);
Children.Add(new Button { Text = "7", Style = plainButton }, 0, 2);
Children.Add(new Button { Text = "8", Style = plainButton }, 1, 2);
Children.Add(new Button { Text = "9", Style = plainButton }, 2, 2);
Children.Add(new Button { Text = "X", Style = orangeButton }, 3, 2);
Children.Add(new Button { Text = "4", Style = plainButton }, 0, 3);
Children.Add(new Button { Text = "5", Style = plainButton }, 1, 3);
Children.Add(new Button { Text = "6", Style = plainButton }, 2, 3);
Children.Add(new Button { Text = "-", Style = orangeButton }, 3, 3);
Children.Add(new Button { Text = "1", Style = plainButton }, 0, 4);
Children.Add(new Button { Text = "2", Style = plainButton }, 1, 4);
Children.Add(new Button { Text = "3", Style = plainButton }, 2, 4);
Children.Add(new Button { Text = "+", Style = orangeButton }, 3, 4);
Children.Add(new Button { Text = ".", Style = plainButton }, 2, 5);
Children.Add(new Button { Text = "=", Style = orangeButton }, 3, 5);
var zeroButton = new Button { Text = "0", Style = plainButton };
Children.Add(zeroButton, 0, 5);
Grid.SetColumnSpan(zeroButton, 2);
}
}
I am using Microsoft Visual Studio Community 2019
Version 16.2.5
VisualStudio.16.Release/16.2.5+29306.81
Microsoft .NET Framework
Version 4.7.03190
Installed Version: Community
Visual C++ 2019 00435-60000-00000-AA475
Microsoft Visual C++ 2019
Application Insights Tools for Visual Studio Package 9.1.00611.1
Application Insights Tools for Visual Studio
Azure App Service Tools v3.0.0 16.2.292.25104
Azure App Service Tools v3.0.0
C# Tools 3.2.1-beta4-19408-03+2fc6a04980f800c59e8ede97e6ae294ff47d666e
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
Devart Code Compare 5.1.183
Devart Code Compare
Copyright (c) 2012-2019 Devart. All rights reserved.
http: //www.devart.com/codecompare/*
Extensibility Message Bus 1.2.0 (d16-2@8b56e20)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.
IntelliCode Extension 1.0
IntelliCode Visual Studio Extension Detailed Info
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers
Microsoft Visual C++ Wizards 1.0
Microsoft Visual C++ Wizards
Microsoft Visual Studio VC Package 1.0
Microsoft Visual Studio VC Package
Mono Debugging for Visual Studio 16.2.6 (4cfc7c3)
Support for debugging Mono processes with Visual Studio.
NuGet Package Manager 5.2.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https: //docs.nuget.org/*
ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info
ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info
ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info
Visual Basic Tools 3.2.1-beta4-19408-03+2fc6a04980f800c59e8ede97e6ae294ff47d666e
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools 10.4 for F# 4.6 16.2.0-beta.19321.1+a24d94ecf97d0d69d4fbe6b8b10cd1f97737fff4
Microsoft Visual F# Tools 10.4 for F# 4.6
Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio
VisualStudio.Mac 1.0
Mac Extension for Visual Studio
Xamarin 16.2.0.95 (d16-2@37df81894)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer 16.2.0.375 (remotes/origin/d16-2@357d38ef4)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin Templates 16.3.117 (59a59e8)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.
Xamarin.Android SDK 9.4.1.1 (d16-2/cec9eb4)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: mono/mono/2019-02@e6f5369c2d2
Java.Interop: xamarin/java.interop/d16-2@d64ada5
LibZipSharp: grendello/LibZipSharp/d16-2@caa0c74
LibZip: nih-at/libzip/rel-1-5-1@b95cf3f
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.27.1@8212a2d
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-2@6f6c969
Xamarin.iOS and Xamarin.Mac SDK 12.14.0.114 (c669116)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Any ideas?
Thank you in advance for your input!
*I am new to this forum, so it won't let me post links. Therefore I have inserted a space between "https:" and the rest of each address, should you care to explore the references...