using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Media; namespace Xamarin.Forms.Platform.WinPhone { public static class FormattedStringExtensions { public static IEnumerable ToInlines(this FormattedString formattedString) { foreach (Span span in formattedString.Spans) yield return span.ToRun(); } public static Run ToRun(this Span span) { var run = new Run { Text = span.Text }; if (span.ForegroundColor != Color.Default) run.Foreground = span.ForegroundColor.ToBrush(); if (!span.IsDefault()) #pragma warning disable 618 run.ApplyFont(span.Font); #pragma warning restore 618 return run; } } public class LabelRenderer : ViewRenderer { bool _fontApplied; protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize) { if (Element == null) return finalSize; double childHeight = Math.Max(0, Math.Min(Element.Height, Control.DesiredSize.Height)); var rect = new Rect(); switch (Element.VerticalTextAlignment) { case TextAlignment.Start: break; default: case TextAlignment.Center: rect.Y = (int)((finalSize.Height - childHeight) / 2); break; case TextAlignment.End: rect.Y = finalSize.Height - childHeight; break; } rect.Height = childHeight; rect.Width = finalSize.Width; Control.Arrange(rect); return finalSize; } protected override void OnElementChanged(ElementChangedEventArgs