2017-06-15 55 views
2

如何的LabelHorizontalOptions属性绑定在Xamarin.Forms`如何,至少从你贴什么xamarin.forms

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

看起来坚实...标签Horizo​​ntalOptions属性绑定。 bindingcontext类在哪里呢? – woelliJ

+0

ohh ...是的,我做到了.....我得到了解决方案,我必须使用价值转换器....顺便说一句,谢谢 – nitu

+0

@nitu你可以发布你的解决方案作为答案?这可能会帮助有同样问题的人=) –

回答

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