Xamarin Forms differences between Android label and UWP
Xamarin Forms differences between Android label and UWP
This screenshot is the result of UWP as Startup Project. It is exactly what I want.
!https://1drv.ms/u/s!An07nml8jWWSwbUM-Y5E7IFVZYlb1A
This screenshot is the result of Android as Startup Project. It is not what I want. The labels don't display the text completely, they do not display all of the fields, and only one image appears which is not the correct one.
!https://1drv.ms/u/s!An07nml8jWWSwbUOmo4tPelZlxknYA
Why such radical differences between the two projects? I know that there are some minor differences but this is too much and not useable. Where do I start to learn how to make the Android version work?
using OFam.ViewModels;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace OFam.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainView : ContentPage
public ObservableCollection<Models.TreeBranches> branches get; set;
public MainView()
InitializeComponent();
branches = new ObservableCollection<Models.TreeBranches>();
ListView viewList = new ListView();
this.Title = "Family Tree";
viewList.ItemTemplate = new DataTemplate(typeof(CustomTreeBranches));
branches.Add(new Models.TreeBranches
BranchNumber = 1,
FullName = "Garland Don Osborne",
Birthday ="1/22/1922",
Father = "Dick Osborn",
Mother = "Hazel Hinton",
Spouse1 = "Iola May Hayes",
Spouse2 = "",
Spouse3 = "",
Child1 = "John Richard Osborne",
Child2 = "Donna May Osborne",
Child3 = "Garland Darrell Osborne",
Child4 = "Orval Ray Osborne",
Residence = "Oakdale, California",
Image = "Photos/GarlandDonOsborne.jpg" );
branches.Add(new Models.TreeBranches
BranchNumber = 2,
FullName = "Iola May Hayes",
Birthday ="11/31/1920",
Father = "Raymond Hayes",
Mother = "Gracie Postoak",
Spouse1 = "Garland Don Osborne",
Spouse2 = "",
Spouse3 = "",
Child1 = "John Richard Osborne",
Child2 = "Donna May Osborne",
Child3 = "Garland Darrell Osborne",
Child4 = "Orval Ray Osborne",
Residence = "Highlands Ranch, Colorado",
Image = "Photos/IolaMayHayes.jpg" );
public class CustomTreeBranches : ViewCell
public CustomTreeBranches()
var img = new Image();
var bdLabel = new Label();
var nameLabel = new Label();
var bnLabel = new Label();
var frLabel = new Label();
var mrLabel = new Label();
var c1Label = new Label();
var c2Label = new Label();
var c3Label = new Label();
var c4Label = new Label();
var s1Label = new Label();
var s2Label = new Label();
var s3Label = new Label();
var rdLabel = new Label();
var sp1Label = new Label()
Text = "Father and Mother",
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Start
;
var sp2Label = new Label()
Text = "Children",
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Start
;
var sp3Label = new Label()
Text = "Spouse(s)",
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center
;
var sp4Label = new Label()
Text = "Latest Residence",
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center
;
var vLayout = new StackLayout();
var hLayout = new StackLayout() BackgroundColor = Color.LavenderBlush ;
img.SetBinding(Image.SourceProperty, new Binding("Image"));
bdLabel.SetBinding(Label.TextProperty, new Binding("Birthday"));
nameLabel.SetBinding(Label.TextProperty, new Binding("FullName"));
frLabel.SetBinding(Label.TextProperty, new Binding("Father"));
mrLabel.SetBinding(Label.TextProperty, new Binding("Mother"));
c1Label.SetBinding(Label.TextProperty, new Binding("Child1"));
c2Label.SetBinding(Label.TextProperty, new Binding("Child2"));
c3Label.SetBinding(Label.TextProperty, new Binding("Child3"));
c4Label.SetBinding(Label.TextProperty, new Binding("Child4"));
s1Label.SetBinding(Label.TextProperty, new Binding("Spouse1"));
s2Label.SetBinding(Label.TextProperty, new Binding("Spouse2"));
s3Label.SetBinding(Label.TextProperty, new Binding("Spouse3"));
rdLabel.SetBinding(Label.TextProperty, new Binding("Residence"));
hLayout.Orientation = StackOrientation.Horizontal;
hLayout.HorizontalOptions = LayoutOptions.Fill;
img.HorizontalOptions = LayoutOptions.End;
img.WidthRequest = 250;
img.HeightRequest = 250;
nameLabel.FontSize = 18;
vLayout.HorizontalOptions = LayoutOptions.Start;
vLayout.Children.Add(nameLabel);
vLayout.Children.Add(bdLabel);
vLayout.Children.Add(sp1Label);
vLayout.Children.Add(frLabel);
vLayout.Children.Add(mrLabel);
vLayout.Children.Add(sp2Label);
vLayout.Children.Add(c1Label);
vLayout.Children.Add(c2Label);
vLayout.Children.Add(c3Label);
vLayout.Children.Add(c4Label);
vLayout.Children.Add(sp3Label);
vLayout.Children.Add(s1Label);
vLayout.Children.Add(s2Label);
vLayout.Children.Add(s3Label);
vLayout.Children.Add(sp4Label);
vLayout.Children.Add(rdLabel);
hLayout.Children.Add(vLayout);
hLayout.Children.Add(img);
View = hLayout;
I don't know about
UWP
specifically, but I can say that the ListView
has a default fixed Height
of 40dpi for its cells. Try just set the HasUnevenRows
property on your ListView's declaring to True
. It'll make each cell render with the size needed for its content.– Diego Rafael Souza
Sep 10 '18 at 0:55
UWP
ListView
Height
HasUnevenRows
True
0
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
The problem is not the Label - on Android it appears that is needs a hint to correctly calculate the height of each row in the ListView. Try setting a HeightRequest value on your ViewCell. I'd also suggest starting with a simpler layout and gradually adding content to it, rather than add in all of your content at once and trying to debug it.
– Jason
Sep 9 '18 at 20:29