Bug 32545 - Stacklayout bug related to label font
Summary: Stacklayout bug related to label font
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 1.4.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-07-28 15:48 UTC by mpollind
Modified: 2016-04-11 09:40 UTC (History)
2 users (show)

Tags: ac stacklayout windows
Is this bug a regression?: ---
Last known good build:


Attachments
Reproduces the Layout bug (3.36 MB, application/x-zip-compressed)
2015-08-06 12:11 UTC, mpollind
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description mpollind 2015-07-28 15:48:30 UTC
This is the exception i'm receiving with this chunk of code. I can remove the color styling and then application will run correctly minus the span styling. 

StackLayout layout = new StackLayout();
                //  errorStack.Children.Clear();
                foreach (string s in errorMessages)
                {
                    Label l = new Label();
                    l.FontSize = FontSize;
                    Span span = new Span();
                    span.Text = s;
                    span.ForegroundColor = Color.Red;
                    l.FormattedText = new FormattedString();
                    l.FormattedText.Spans.Add(span);
                    layout.Children.Add(l);

                }
                ((ContentView)this.Content).Content = layout;

{System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
   at Xamarin.Forms.Platform.WinPhone.FontExtensions.ApplyFont(TextBlock self, Font font)
   at Xamarin.Forms.Platform.WinPhone.LabelRenderer.UpdateFont(TextBlock textBlock)
   at Xamarin.Forms.Platform.WinPhone.LabelRenderer.OnElementChanged(ElementChangedEventArgs`1 e)
   at Xamarin.Forms.Platform.WinPhone.VisualElementRenderer`2.SetElement(VisualElement element)
   at Xamarin.Forms.Platform.WinPhone.RendererFactory.GetRenderer(VisualElement view)
   at Xamarin.Forms.Platform.WinPhone.VisualElementPackager.HandleChildAdded(Object sender, ElementEventArgs e)
   at Xamarin.Forms.Platform.WinPhone.VisualElementPackager.Load()
   at Xamarin.Forms.Platform.WinPhone.VisualElementRenderer`2.SetElement(VisualElement element)
   at Xamarin.Forms.Platform.WinPhone.RendererFactory.GetRenderer(VisualElement view)
   at Xamarin.Forms.Platform.WinPhone.VisualElementPackager.HandleChildAdded(Object sender, ElementEventArgs e)
   at Xamarin.Forms.Element.OnChildAdded(Element child)
   at Xamarin.Forms.Layout.OnInternalAdded(View view)
   at Xamarin.Forms.Layout.InternalChildrenOnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
   at System.Collections.ObjectModel.Collection`1.Add(T item)
   at Xamarin.Forms.ContentView.set_Content(View value)
   at LcpMobile.Forms.CustomUI.ErrorList.Validate[T](T instance, IValidator`1 validator, List`1 focus)}
Comment 1 mpollind 2015-07-28 15:58:41 UTC
I actually resolved this issue with this chunk. This resolved both of my problems with windows phone and IOS. IOS in this case will not display any errors. 

  foreach (string s in errorMessages)
                {
                    layout.Children.Add(new Label { FormattedText = new FormattedString { Spans = { new Span() { Text = s , ForegroundColor = Color.Red} } } });

                }
Comment 2 Rui Marinho 2015-07-29 12:43:53 UTC
Thank you for taking the time to submit the bug. We tried to reproduce the issue you reported but were unable given the description. If you could please attach a reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue we would very much appreciate it.

This was the sample we used:

>            var fontsize = 12;
>            var errorMessages = new List<string>();
>            for (int i = 0; i < 20; i++)
>            {
>                errorMessages.Add(i.ToString());
>
>           }
>            StackLayout layout = new StackLayout();
>            //  errorStack.Children.Clear();
>            foreach (string s in errorMessages)
>            {
>                Label l = new Label();
>                l.FontSize = fontsize;
>                Span span = new Span();
>                span.Text = s;
>                span.ForegroundColor = Color.Red;
>                l.FormattedText = new FormattedString();
>                l.FormattedText.Spans.Add(span);
>                layout.Children.Add(l);
>            }
>            MainPage = new ContentPage { Content = layout };

Warm regards,
Xamarin Forms Team
Comment 3 mpollind 2015-08-06 12:11:28 UTC
Created attachment 12389 [details]
Reproduces the Layout bug
Comment 4 Rui Marinho 2015-08-10 11:48:46 UTC
Thanks, we are able to confirm the issue
Comment 5 Jason Smith [MSFT] 2016-04-11 09:40:40 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.
 
For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards,
Xamarin Forms Team