0
votes

I'm learning xamarin forms and binding. I would like to bind the HorizontalTextAlignment xaml property to the viewmodel property MessagePosition:

<Label Text="{Binding Message}" HorizontalTextAlignment="{Binding MessagePosition}"   />

where MessagePosition has a value of "Start" or "End". Unfortunately, it does not seem to work.

Explicitly setting:

<Label Text="{Binding Message}" HorizontalTextAlignment="Start"   />

or

<Label Text="{Binding Message}" HorizontalTextAlignment="End"   />

does work. The Text binding on the viewmodel property Message works as well. Sorry if duplicate question...thanks for your time.

1
what is the type pf MessagePosition property? I think it should be of type TextAlignment or somethingMohamedHamza
What does your ViewModel look like? And why isn't it working? Nothing happens or you get an error?Gerald Versluis

1 Answers

4
votes

You should set the Alignment to a value of TextAlignment.

XAML :

<Label Text="{Binding Message}" HorizontalTextAlignment="{Binding HPos}" />

ViewModel :

private TextAlignment _hPos;
public TextAlignment HPos 
{ 
   get { return _hPos; } 
   set 
   { 
      _hPos = value; 
      OnPropertyChanged(); 
   }
}