void UpdateUi(ExtendedLabel view, TextView control)
        {
            if (!string.IsNullOrEmpty(view.FontName))
            {
                control.Typeface = TrySetFont(view.FontName);
            }

            if (!string.IsNullOrEmpty(view.FontNameAndroid))
            {
                control.Typeface = TrySetFont(view.FontNameAndroid); ;
            }

            if (view.FontSize > 0)
            {
                control.TextSize = (float)view.FontSize;
            }

            if (view.IsUnderline)
            {
                control.PaintFlags = control.PaintFlags | PaintFlags.UnderlineText;
            }

            if (view.IsStrikeThrough)
            {
                control.PaintFlags = control.PaintFlags | PaintFlags.StrikeThruText;
            }
        }
        public ExtendedLabelPage()
        {
            InitializeComponent();
            BindingContext = ViewModelLocator.Main;

            var label = new ExtendedLabel
            {
                Text = "From code, using Device.OnPlatform, Underlined",
                FontName = "Open 24 Display St.ttf",
                FriendlyFontName = Device.OnPlatform<String>("", "", "Open 24 Display St"),
                IsUnderline = true,
                FontSize = 22,
            };

            var label2 = new ExtendedLabel
            {
                Text = "From code, Strikethrough",
                FontName = "Open 24 Display St.ttf",
                FriendlyFontName = Device.OnPlatform<String>("", "", "Open 24 Display St"),
                IsUnderline = false,
                IsStrikeThrough = true,
                FontSize = 22,
            };

            stkRoot.Children.Add(label);
            stkRoot.Children.Add(label2);
        }
        /// <summary>
        /// Updates the UI.
        /// </summary>
        /// <param name="view">
        /// The view.
        /// </param>
        /// <param name="control">
        /// The control.
        /// </param>
        private static void UpdateUi(ExtendedLabel view, UILabel control)
        {
            if (!string.IsNullOrEmpty(view.FontName))
            {
                var font = UIFont.FromName(
                    view.FontName,
                    (view.FontSize > 0) ? (float)view.FontSize : 12.0f);

                if (font != null)
                {
                    control.Font = font;
                }
            }

            if (!string.IsNullOrEmpty(view.FontNameIOS))
            {
                var font = UIFont.FromName(
                    view.FontNameIOS,
                   (view.FontSize > 0) ? (float)view.FontSize : 12.0f);

                if (font != null)
                {
                    control.Font = font;
                }
            }

            if (view.IsUnderline) {
                control.AttributedText = new NSAttributedString (
                    control.Text,
                    underlineStyle: NSUnderlineStyle.Single);
            }
        }
        public ExtendedLabelPage()
        {
            InitializeComponent();
            BindingContext = ViewModelLocator.Main;

            var label = new ExtendedLabel
            {
                Text = "and From code",
                FontName = Device.OnPlatform<String>("Roboto-Light", "fonts/Roboto-Light.ttf", "Courier New"),
                IsUnderline = true,
                FontSize = 22,
            };

            var label2 = new ExtendedLabel
            {
                Text = "and From code",
                FontName = Device.OnPlatform<String>("Roboto-Light", "fonts/Roboto-Light.ttf", "Courier New"),
                IsUnderline = false,
                IsStrikeThrough = true,
                FontSize = 22,
            };

            stkRoot.Children.Add(label);
            stkRoot.Children.Add(label2);
        }
        /// <summary>
        /// Updates the UI.
        /// </summary>
        /// <param name="view">
        /// The view.
        /// </param>
        /// <param name="control">
        /// The control.
        /// </param>
        private static void UpdateUi(ExtendedLabel view, UILabel control)
        {
            if (view.FontSize > 0)
            {
                control.Font = UIFont.FromName(control.Font.Name,(float)view.FontSize);
            }

            if (!string.IsNullOrEmpty(view.FontName))
            {
                string fontName = view.FontName;
                //if extension given then remove it for iOS
                if (fontName.LastIndexOf(".", System.StringComparison.Ordinal) == fontName.Length - 4)
                {
                    fontName = fontName.Substring(0, fontName.Length - 4);
                }

                var font = UIFont.FromName(
                    fontName, control.Font.PointSize);

                if (font != null)
                {
                    control.Font = font;
                }
            }

            //======= This is for backward compatability with obsolete attrbute 'FontNameIOS' ========
            if (!string.IsNullOrEmpty(view.FontNameIOS))
            {
                var font = UIFont.FromName(
                    view.FontNameIOS,
                   (view.FontSize > 0) ? (float)view.FontSize : 12.0f);

                if (font != null)
                {
                    control.Font = font;
                }
            }
            //====== End of obsolete section ==========================================================

            var attrString = new NSMutableAttributedString(control.Text);

            if (view.IsUnderline)
            {
                //control.AttributedText = new NSAttributedString(
                //    control.Text,
                //    underlineStyle: NSUnderlineStyle.Single);

                attrString.AddAttribute(UIStringAttributeKey.UnderlineStyle, NSNumber.FromInt32((int)NSUnderlineStyle.Single), new NSRange(0, attrString.Length));
            }

            if (view.IsStrikeThrough)
            {
                attrString.AddAttribute(UIStringAttributeKey.StrikethroughStyle, NSNumber.FromInt32((int)NSUnderlineStyle.Single), new NSRange(0, attrString.Length));
            }

            control.AttributedText = attrString;
        }
        public ExtendedLabelPage()
        {
            InitializeComponent();

            BindingContext = ViewModelLocator.Main;

            var label = new ExtendedLabel
            {
                Text = "From code, using Device.OnPlatform, Underlined",
                FontName = "Open 24 Display St.ttf",
                FriendlyFontName = Device.OnPlatform("", "", "Open 24 Display St"),
                IsUnderline = true,
                FontSize = 22,
            };

            var label2 = new ExtendedLabel
            {
                Text = "From code, Strikethrough",
                FontName = "Open 24 Display St.ttf",
                FriendlyFontName = Device.OnPlatform("", "", "Open 24 Display St"),
                IsUnderline = false,
                IsStrikeThrough = true,
                FontSize = 22,
            };

			var font = Font.OfSize("Open 24 Display St", 22);

			var label3 = new ExtendedLabel
			{
				Text = "From code, Strikethrough and using Font property",
                TextColor = Device.OnPlatform(Color.Black,Color.White, Color.White),
				IsUnderline = false,
				IsStrikeThrough = true
			};

            var label4 = new ExtendedLabel
            {
                IsDropShadow = true,
                Text = "From code, Dropshadow with TextColor",
                TextColor = Color.Green
            };

            var label5 = new Label
            {
                Text = "Standard Label created using code",
            };

			label3.Font = font;

            stkRoot.Children.Add(label4);
            stkRoot.Children.Add(label3);
            stkRoot.Children.Add(label2);
            stkRoot.Children.Add(label);
            stkRoot.Children.Add(label5);
        }
 void UpdateUi(ExtendedLabel view, TextView control)
 {
     if (!string.IsNullOrEmpty (view.FontName)) {
         control.Typeface = 	TrySetFont (view.FontName);
     }
     if (!string.IsNullOrEmpty (view.FontNameAndroid)) {
         control.Typeface = 	TrySetFont (view.FontNameAndroid);;
     }
     if (view.FontSize > 0)
         control.TextSize = (float)view.FontSize;
 }
        public ExtendedLabelPage()
        {
            InitializeComponent ();
            BindingContext = ViewModelLocator.Main;

            var label = new ExtendedLabel () {
                Text = "and From code",
            };
            label.FontName = Device.OnPlatform<String>("Roboto-Light", "fonts/Roboto-Light.ttf", "");
            label.FontSize = 22;
            stkRoot.Children.Add (label);
        }
        /// <summary>
        /// Updates the UI.
        /// </summary>
        /// <param name="view">
        /// The view.
        /// </param>
        /// <param name="control">
        /// The control.
        /// </param>
        private static void UpdateUi(ExtendedLabel view, TextBlock control)
        {
            if (!string.IsNullOrEmpty(view.FontName))
            {
                control.FontFamily = new FontFamily(view.FontName);
                control.FontSize = (view.FontSize > 0) ? (float)view.FontSize : 12.0f;
            }

            if (view.IsUnderline)
            {
                control.TextDecorations = TextDecorations.Underline;
            }
        }
Exemple #10
0
        /// <summary>
        /// Updates the UI.
        /// </summary>
        /// <param name="view">
        /// The view.
        /// </param>
        /// <param name="control">
        /// The control.
        /// </param>
        private static void UpdateUi(ExtendedLabel view, TextBlock control)
        {
            if (!string.IsNullOrEmpty(view.FontName))
            {
                control.FontFamily = new FontFamily(view.FontName);
                control.FontSize   = (view.FontSize > 0) ? (float)view.FontSize : 12.0f;
            }

            if (view.IsUnderline)
            {
                control.TextDecorations = TextDecorations.Underline;
            }
        }
        /// <summary>
        /// Updates the UI.
        /// </summary>
        /// <param name="view">
        /// The view.
        /// </param>
        /// <param name="control">
        /// The control.
        /// </param>
        private static void UpdateUi(ExtendedLabel view, UILabel control)
        {
            if (!string.IsNullOrEmpty(view.FontName))
            {
                var font = UIFont.FromName(
                    view.FontName,
                    (view.FontSize > 0) ? (float)view.FontSize : 12.0f);

                if (font != null)
                {
                    control.Font = font;
                }
            }

            if (!string.IsNullOrEmpty(view.FontNameIOS))
            {
                var font = UIFont.FromName(
                    view.FontNameIOS,
                   (view.FontSize > 0) ? (float)view.FontSize : 12.0f);

                if (font != null)
                {
                    control.Font = font;
                }
            }

            var attrString = new NSMutableAttributedString(control.Text);

            if (view.IsUnderline)
            {
                //control.AttributedText = new NSAttributedString(
                //    control.Text,
                //    underlineStyle: NSUnderlineStyle.Single);

                attrString.AddAttribute(UIStringAttributeKey.UnderlineStyle, NSNumber.FromInt32((int)NSUnderlineStyle.Single), new NSRange(0, attrString.Length));
            }

            if (view.IsStrikeThrough)
            {
                attrString.AddAttribute(UIStringAttributeKey.StrikethroughStyle, NSNumber.FromInt32((int)NSUnderlineStyle.Single), new NSRange(0, attrString.Length));
            }

            control.AttributedText = attrString;
        }
        /// <summary>
        /// Updates the UI.
        /// </summary>
        /// <param name="view">
        /// The view.
        /// </param>
        /// <param name="control">
        /// The control.
        /// </param>
        private void UpdateUi(ExtendedLabel view, TextBlock control)
        {
            if (!string.IsNullOrEmpty(view.FontName))
            {
                control.FontFamily = new FontFamily(view.FontName);
                control.FontSize = (view.FontSize > 0) ? (float)view.FontSize : 12.0f;
            }

            if (view.IsUnderline)
            {
                control.TextDecorations = TextDecorations.Underline;
            }

            if (view.IsStrikeThrough)
            {
                //isn't perfect, but it's a start 
                var border = new Border() { Height = 1, Width = this.Control.ActualWidth, Background = control.Foreground, HorizontalAlignment = HorizontalAlignment.Center };
                Canvas.SetTop(border, (this.Control.ActualHeight / 2) - 0.5);
                ((Xamarin.Forms.Platform.WinPhone.VisualElementRenderer<Xamarin.Forms.Label, System.Windows.Controls.TextBlock>)(this)).Children.Add(border);

            }
        }
        void UpdateUi(ExtendedLabel view, TextView control)
        {
            if (!string.IsNullOrEmpty(view.FontName))
            {
                string filename = view.FontName;
                //if no extension given then assume and add .ttf
                if (filename.LastIndexOf(".", System.StringComparison.Ordinal) != filename.Length - 4)
                {
                    filename = string.Format("{0}.ttf", filename);
                }
                control.Typeface = TrySetFont(filename);
            }

            //======= This is for backward compatability with obsolete attrbute 'FontNameAndroid' ========
            if (!string.IsNullOrEmpty(view.FontNameAndroid))
            {
                control.Typeface = TrySetFont(view.FontNameAndroid); ;
            }
            //====== End of obsolete section ==========================================================

            if (view.FontSize > 0)
            {
                control.TextSize = (float)view.FontSize;
            }

            if (view.IsUnderline)
            {
                control.PaintFlags = control.PaintFlags | PaintFlags.UnderlineText;
            }

            if (view.IsStrikeThrough)
            {
                control.PaintFlags = control.PaintFlags | PaintFlags.StrikeThruText;
            }

        }
Exemple #14
0
        /// <summary>
        /// Updates the UI.
        /// </summary>
        /// <param name="view">
        /// The view.
        /// </param>
        /// <param name="control">
        /// The control.
        /// </param>
        private void UpdateUi(ExtendedLabel view, TextBlock control)
        {
            if (!string.IsNullOrEmpty(view.FontName))
            {
                control.FontFamily = new FontFamily(view.FontName);
                control.FontSize   = (view.FontSize > 0) ? (float)view.FontSize : 12.0f;
            }

            if (view.IsUnderline)
            {
                control.TextDecorations = TextDecorations.Underline;
            }

            if (view.IsStrikeThrough)
            {
                //isn't perfect, but it's a start
                var border = new Border()
                {
                    Height = 1, Width = this.Control.ActualWidth, Background = control.Foreground, HorizontalAlignment = HorizontalAlignment.Center
                };
                Canvas.SetTop(border, (this.Control.ActualHeight / 2) - 0.5);
                ((Xamarin.Forms.Platform.WinPhone.VisualElementRenderer <Xamarin.Forms.Label, System.Windows.Controls.TextBlock>)(this)).Children.Add(border);
            }
        }
        /// <summary>
        /// Updates the UI.
        /// </summary>
        /// <param name="view">
        /// The view.
        /// </param>
        /// <param name="control">
        /// The control.
        /// </param>
        private void UpdateUi(ExtendedLabel view, TextBlock control)
        {
            if (view.FontSize > 0)
            {
                control.FontSize = (float)view.FontSize;
            }
            //control.FontSize = (view.FontSize > 0) ? (float)view.FontSize : 12.0f;

            ////need to do this ahead of font change due to unexpected behaviour if done later.
            if (view.IsStrikeThrough)
            {
                //isn't perfect, but it's a start
                var border = new Border
                {
                    Height              = 2,
                    Width               = this.Control.ActualWidth,
                    Background          = control.Foreground,
                    HorizontalAlignment = HorizontalAlignment.Center
                };
                Canvas.SetTop(border, control.FontSize * .72);
                //Canvas.SetTop(border, (this.Control.ActualHeight / 2) - 0.5);
                this.Children.Add(border);

                //// STILL IN DEVELOPMENT === alternative and possibly more flexible grid method - Got stuck making this controls parent the grid below

                //var strikeThroughGrid = new System.Windows.Controls.Grid();
                //strikeThroughGrid.VerticalAlignment = VerticalAlignment.Top;
                //strikeThroughGrid.HorizontalAlignment = HorizontalAlignment.Left;
                ////define rows
                //var colDef1 = new System.Windows.Controls.RowDefinition { Height = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star) };
                //var colDef2 = new System.Windows.Controls.RowDefinition { Height = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star) };
                //strikeThroughGrid.RowDefinitions.Add(colDef1);
                //strikeThroughGrid.RowDefinitions.Add(colDef2);

                ////add textblock
                //strikeThroughGrid.Children.Add(control);
                //System.Windows.Controls.Grid.SetRowSpan(control,2);

                ////add border
                //var strikethroughBorder = new Border{BorderThickness = new System.Windows.Thickness(0,0,0,2) , BorderBrush = control.Foreground , Padding = new System.Windows.Thickness(0,0,0,control.FontSize*0.3)};
                //strikeThroughGrid.Children.Add(strikethroughBorder);
            }

            if (!string.IsNullOrEmpty(view.FontName))
            {
                string filename = view.FontName;
                //if no extension given then assume and add .ttf
                if (filename.LastIndexOf(".", StringComparison.Ordinal) != filename.Length - 4)
                {
                    filename = string.Format("{0}.ttf", filename);
                }

                if (IsLocalFontFileExists(filename)) //only substitute custom font if exists
                {
                    control.FontFamily =
                        new FontFamily(string.Format(@"\Assets\Fonts\{0}#{1}", filename,
                                                     string.IsNullOrEmpty(view.FriendlyFontName)
                                ? filename.Substring(0, filename.Length - 4)
                                : view.FriendlyFontName));
                }
            }

            if (view.IsUnderline)
            {
                control.TextDecorations = TextDecorations.Underline;
            }
        }
        /// <summary>
        /// Updates the UI.
        /// </summary>
        /// <param name="view">
        /// The view.
        /// </param>
        /// <param name="control">
        /// The control.
        /// </param>
        private void UpdateUi(ExtendedLabel view, TextBlock control)
        {
            if (view.FontSize > 0)
                control.FontSize = (float) view.FontSize;
            //control.FontSize = (view.FontSize > 0) ? (float)view.FontSize : 12.0f;

            ////need to do this ahead of font change due to unexpected behaviour if done later.
            if (view.IsStrikeThrough)
            {             
                //isn't perfect, but it's a start
                var border = new Border
                {
                    Height = 2, 
                    Width = this.Control.ActualWidth, 
                    Background = control.Foreground, 
                    HorizontalAlignment = HorizontalAlignment.Center
                };
                Canvas.SetTop(border, control.FontSize*.72);
                //Canvas.SetTop(border, (this.Control.ActualHeight / 2) - 0.5);
                this.Children.Add(border);

                //// STILL IN DEVELOPMENT === alternative and possibly more flexible grid method - Got stuck making this controls parent the grid below

                //var strikeThroughGrid = new System.Windows.Controls.Grid();
                //strikeThroughGrid.VerticalAlignment = VerticalAlignment.Top;
                //strikeThroughGrid.HorizontalAlignment = HorizontalAlignment.Left;
                ////define rows
                //var colDef1 = new System.Windows.Controls.RowDefinition { Height = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star) };
                //var colDef2 = new System.Windows.Controls.RowDefinition { Height = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star) };
                //strikeThroughGrid.RowDefinitions.Add(colDef1);
                //strikeThroughGrid.RowDefinitions.Add(colDef2);

                ////add textblock
                //strikeThroughGrid.Children.Add(control);
                //System.Windows.Controls.Grid.SetRowSpan(control,2);

                ////add border
                //var strikethroughBorder = new Border{BorderThickness = new System.Windows.Thickness(0,0,0,2) , BorderBrush = control.Foreground , Padding = new System.Windows.Thickness(0,0,0,control.FontSize*0.3)};
                //strikeThroughGrid.Children.Add(strikethroughBorder);

            }

            if (!string.IsNullOrEmpty(view.FontName))
            {
                string filename = view.FontName;
                //if no extension given then assume and add .ttf
                if (filename.LastIndexOf(".", StringComparison.Ordinal) != filename.Length - 4)
                {
                    filename = string.Format("{0}.ttf", filename);
                }

                if (IsLocalFontFileExists(filename)) //only substitute custom font if exists
                    control.FontFamily =
                        new FontFamily(string.Format(@"\Assets\Fonts\{0}#{1}", filename,
                            string.IsNullOrEmpty(view.FriendlyFontName)
                                ? filename.Substring(0, filename.Length - 4)
                                : view.FriendlyFontName));
            }

            if (view.IsUnderline)
                control.TextDecorations = TextDecorations.Underline;
        }