如何在xamarin.forms中绑定Label的Horizo​​ntalOptions属性 [英] how to bind HorizontalOptions property of label in xamarin.forms

查看:60
本文介绍了如何在xamarin.forms中绑定Label的Horizo​​ntalOptions属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Xamarin.Forms中绑定LabelHorizontalOptions属性

How to bind the HorizontalOptions attribute of Label in Xamarin.Forms`

<Label TextColor="#01B6FF"  Text="{Binding RecepientFullName}" FontSize="Small" HorizontalOptions="{Binding TextAlign} />`

推荐答案

    <ContentPage.Resources>
    <ResourceDictionary >
        <local:ChatTextAlignmentConverter x:Key="ChatTextAlignmentConverter">
        </local:ChatTextAlignmentConverter>
    </ResourceDictionary>
</ContentPage.Resources>


<Frame  Margin="10,0,10,0" Padding="10,5,10,5"  HorizontalOptions="{Binding TextAlign, Converter={StaticResource ChatTextAlignmentConverter}}" BackgroundColor="{Binding BackgroundColor}"/>


 public class ChatTextAlignmentConverter: IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value != null)
        {
            string valueAsString = value.ToString();
            switch (valueAsString)
            {
                case ("EndAndExpand"):
                    {
                        return LayoutOptions.EndAndExpand;
                    }
                case ("StartAndExpand"):
                    {
                        return LayoutOptions.StartAndExpand;
                    }
                default:
                    {
                        return LayoutOptions.StartAndExpand;
                    }
            }
        }
        else
        {
            return LayoutOptions.StartAndExpand;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return null;
    }
}

这篇关于如何在xamarin.forms中绑定Label的Horizo​​ntalOptions属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆