gpt4 book ai didi

c# - 如何在 xamarin.forms 中绑定(bind)标签的 Horizo​​ntalOptions 属性

转载 作者:行者123 更新时间:2023-11-30 17:33:08 25 4
gpt4 key购买 nike

如何在 Xamarin.Forms 中绑定(bind) LabelHorizo​​ntalOptions 属性`

<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;
}
}

关于c# - 如何在 xamarin.forms 中绑定(bind)标签的 Horizo​​ntalOptions 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44565205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com