maui-linux/Xamarin.Forms.Core/Span.cs

160 строки
4.8 KiB
C#

using System;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms
{
[ContentProperty("Text")]
public sealed class Span : GestureElement, IFontElement, IStyleElement, ITextElement, ILineHeightElement, IDecorableTextElement
{
internal readonly MergedStyle _mergedStyle;
public Span()
{
_mergedStyle = new MergedStyle(GetType(), this);
}
public static readonly BindableProperty StyleProperty = BindableProperty.Create(nameof(Style), typeof(Style), typeof(Span), default(Style),
propertyChanged: (bindable, oldvalue, newvalue) => ((Span)bindable)._mergedStyle.Style = (Style)newvalue, defaultBindingMode: BindingMode.OneTime);
public static readonly BindableProperty TextDecorationsProperty = DecorableTextElement.TextDecorationsProperty;
public Style Style
{
get { return (Style)GetValue(StyleProperty); }
set { SetValue(StyleProperty, value); }
}
public static readonly BindableProperty BackgroundColorProperty
= BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(Span), default(Color), defaultBindingMode: BindingMode.OneTime);
public Color BackgroundColor
{
get { return (Color)GetValue(BackgroundColorProperty); }
set { SetValue(BackgroundColorProperty, value); }
}
public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty;
public Color TextColor
{
get { return (Color)GetValue(TextElement.TextColorProperty); }
set { SetValue(TextElement.TextColorProperty, value); }
}
[Obsolete("Foreground is obsolete as of version 3.1.0. Please use the TextColor property instead.")]
public static readonly BindableProperty ForegroundColorProperty = TextColorProperty;
#pragma warning disable 618
public Color ForegroundColor
{
get { return (Color)GetValue(ForegroundColorProperty); }
set { SetValue(ForegroundColorProperty, value); }
}
#pragma warning restore 618
public static readonly BindableProperty TextProperty
= BindableProperty.Create(nameof(Text), typeof(string), typeof(Span), "", defaultBindingMode: BindingMode.OneTime);
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public static readonly BindableProperty FontProperty = FontElement.FontProperty;
public static readonly BindableProperty FontFamilyProperty = FontElement.FontFamilyProperty;
public static readonly BindableProperty FontSizeProperty = FontElement.FontSizeProperty;
public static readonly BindableProperty FontAttributesProperty = FontElement.FontAttributesProperty;
public static readonly BindableProperty LineHeightProperty = LineHeightElement.LineHeightProperty;
[Obsolete("Font is obsolete as of version 1.3.0. Please use the Font properties directly.")]
public Font Font
{
get { return (Font)GetValue(FontElement.FontProperty); }
set { SetValue(FontElement.FontProperty, value); }
}
public FontAttributes FontAttributes
{
get { return (FontAttributes)GetValue(FontElement.FontAttributesProperty); }
set { SetValue(FontElement.FontAttributesProperty, value); }
}
public string FontFamily
{
get { return (string)GetValue(FontElement.FontFamilyProperty); }
set { SetValue(FontElement.FontFamilyProperty, value); }
}
[TypeConverter(typeof(FontSizeConverter))]
public double FontSize
{
get { return (double)GetValue(FontElement.FontSizeProperty); }
set { SetValue(FontElement.FontSizeProperty, value); }
}
public TextDecorations TextDecorations
{
get { return (TextDecorations)GetValue(TextDecorationsProperty); }
set { SetValue(TextDecorationsProperty, value); }
}
public double LineHeight
{
get { return (double)GetValue(LineHeightElement.LineHeightProperty); }
set { SetValue(LineHeightElement.LineHeightProperty, value); }
}
protected override void OnBindingContextChanged()
{
this.PropagateBindingContext(GestureRecognizers);
base.OnBindingContextChanged();
}
void IFontElement.OnFontFamilyChanged(string oldValue, string newValue)
{
}
void IFontElement.OnFontSizeChanged(double oldValue, double newValue)
{
}
double IFontElement.FontSizeDefaultValueCreator() =>
Device.GetNamedSize(NamedSize.Default, new Label());
void IFontElement.OnFontAttributesChanged(FontAttributes oldValue, FontAttributes newValue)
{
}
void IFontElement.OnFontChanged(Font oldValue, Font newValue)
{
}
void ITextElement.OnTextColorPropertyChanged(Color oldValue, Color newValue)
{
}
internal override void ValidateGesture(IGestureRecognizer gesture)
{
switch (gesture)
{
case ClickGestureRecognizer click:
case TapGestureRecognizer tap:
case null:
break;
default:
throw new InvalidOperationException($"{gesture.GetType().Name} is not supported on a {nameof(Span)}");
}
}
void ILineHeightElement.OnLineHeightChanged(double oldValue, double newValue)
{
}
}
}