protected override void OnAttached()
        {
            TypefaceEffect typefaceEffect = (TypefaceEffect)Element.Effects.First(e => e is TypefaceEffect);

            string fontFamily;

            switch (typefaceEffect.Name)
            {
            case TypefaceEffect.InstalledTypeface.MonospaceTypewriter:
                fontFamily = "MonospaceTypewriter";
                break;

            case TypefaceEffect.InstalledTypeface.Immortal:
                fontFamily = "Immortal";
                break;

            default:
                fontFamily = null;
                break;
            }

            try
            {
                switch (Control)
                {
                case UILabel lbl:
                    Xamarin.Forms.Label lblElem = Element as Xamarin.Forms.Label;
                    if (lblElem != null)
                    {
                        prevUIFont         = lbl.Font;
                        lbl.Font           = UIFont.FromName(fontFamily, new System.nfloat(lblElem.FontSize));
                        lblElem.FontFamily = lbl.Font.FamilyName;
                    }
                    break;

                case UITextField tf:
                    Xamarin.Forms.Picker tfElem = Element as Xamarin.Forms.Picker;
                    if (tfElem != null)
                    {
                        prevUIFont = tf.Font;
                        tf.Font    = UIFont.FromName(fontFamily, new System.nfloat(12f));
                    }
                    break;

                case UIButton b:
                    Xamarin.Forms.Button bElem = Element as Xamarin.Forms.Button;
                    if (bElem != null)
                    {
                        prevUIFont       = b.Font;
                        b.Font           = UIFont.FromName(fontFamily, new System.nfloat(bElem.FontSize));
                        bElem.FontFamily = b.Font.FamilyName;
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
            }
        }
Exemplo n.º 2
0
        protected override void OnAttached()
        {
            try
            {
                TypefaceEffect typefaceEffect = (TypefaceEffect)Element.Effects.First(e => e is TypefaceEffect);

                FontFamily fontFamily;
                switch (typefaceEffect.Name)
                {
                case TypefaceEffect.InstalledTypeface.MonospaceTypewriter:
                    fontFamily = MonospaceTypewriterFont.Value;
                    break;

                case TypefaceEffect.InstalledTypeface.Immortal:
                    fontFamily = ImmortalFont.Value;
                    break;

                default:
                    fontFamily = null;
                    break;
                }

                switch (Control)
                {
                case TextBlock tb:
                    tb.FontFamily = fontFamily;
                    break;

                case Button b:
                    b.FontFamily = fontFamily;
                    break;

                case ComboBox cb:
                    cb.FontFamily = fontFamily;
                    break;

                case TextBox tbx:
                    tbx.FontFamily = fontFamily;
                    break;

                case ToggleSwitch tsw:
                    tsw.FontFamily = fontFamily;
                    break;

                case Control cntr:
                    cntr.FontFamily = fontFamily;
                    break;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
            }
        }
        protected override void OnAttached()
        {
            try
            {
                TypefaceEffect typefaceEffect = (TypefaceEffect)Element.Effects.First(e => e is TypefaceEffect);
                Typeface       typeface;
                switch (typefaceEffect.Name)
                {
                case TypefaceEffect.InstalledTypeface.MonospaceTypewriter:
                    typeface = MonospaceTypewriterTypeface.Value;
                    break;

                case TypefaceEffect.InstalledTypeface.Immortal:
                    typeface = ImmortalTypeface.Value;
                    break;

                default:
                    typeface = null;
                    break;
                }

                if (typeface == null)
                {
                    return;
                }

                switch (Control)
                {
                case TextView lbl:
                    prevTypeface = lbl.Typeface;
                    lbl.Typeface = typeface;
                    break;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
            }
        }