【发布时间】:2018-09-29 21:09:43
【问题描述】:
我只是想让转换器将 TextAlignment 选项枚举绑定到字符串属性.. 经过长时间的搜索,我发现转换器是解决方案,但我仍然无法针对我的情况做特定的解决方案.. 有什么帮助吗? 我用这个代码
EnumtoStringConverter.cs
class EnumtoStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var returnValue = value as string;
if (returnValue == "Start")
return "Start";
else if (returnValue == "Center")
return "Center";
else if (returnValue == "End")
return "End";
return returnValue;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
}
}
Xaml
<StackLayout Orientation="Horizontal" HeightRequest="40" HorizontalOptions="Fill" BackgroundColor="White">
<controls:ExtendedButton HorizontalContentAlignment="{Binding HoriRLLR}" Margin="20,0,0,0" Image="house.png" HorizontalOptions="FillAndExpand" BackgroundColor="White" Text="{translator:Translate HomeSpacing}"></controls:ExtendedButton>
</StackLayout>
HoriRLLR 是我要绑定的字符串属性
我知道我应该在 convert 方法中编写代码,但我不知道我错过了什么?如果我的方式正确吗?
【问题讨论】:
-
这可能会有所帮助...stackoverflow.com/questions/30095689/…
-
很好,但是当我绑定属性时没有任何改变:/
-
在您的
ExtendedButton类中,可绑定属性HorizontalContentAlignment的类型是什么? -
@apineda 枚举,它是 Xlabs 组件
标签: c# xamarin.forms