Xamarin 有没有一种方法可以覆盖XF中标签的文本属性?

Xamarin 有没有一种方法可以覆盖XF中标签的文本属性?,xamarin,xamarin.forms,Xamarin,Xamarin.forms,以下是我拥有的代码: public partial class UpperLabel : Label { public UpperLabel() { this.SetDynamicResource(Label.FontFamilyProperty, "Roboto-Regular"); this.SetDynamicResource(Label.FontSizeProperty, "HeaderTextFontSize

以下是我拥有的代码:

public partial class UpperLabel : Label
{
    public UpperLabel()
    {
        this.SetDynamicResource(Label.FontFamilyProperty, "Roboto-Regular");
        this.SetDynamicResource(Label.FontSizeProperty, "HeaderTextFontSize");
        this.SetDynamicResource(Label.TextColorProperty, "HeaderTextColor");
    }
}
我的问题是,我想让它,使标签总是显示大写文本。这是我想做的,但我相信这是不可能的,因为我有代码

    public static readonly BindableProperty TextProperty =
        BindableProperty.Create(nameof(Text), typeof(string), typeof(Label), default(string));


    public string Text {
        get
        {
            var value = (string)GetValue(TextProperty);
            return !string.IsNullOrEmpty(value) ? value.ToUpper() : value;
        }
        set
        {
            SetValue(TextProperty, value);
        }
    }
注意:我意识到一个建议是创建一个名为Text1的属性,然后将该属性更改为upper并设置Text。另外还有其他解决方案,例如在具有文本属性的网格中包含标签。但是我仍然想知道是否可以做些什么使标签变成大写。

你可以这样做

    new public static readonly BindableProperty TextProperty =
    BindableProperty.Create(nameof(Text), typeof(string), typeof(CustomLabel), default(string),propertyChanged: TextPropertyChanged);

    private static void TextPropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
        var label = (CustomLabel)bindable;
        label.Text = newValue.ToString().ToUpper();
    }