i am having trouble with aligning the text on an expanded picker to the centre and i would have thought it would be something like this...
and here is the picker on the emulator...
How would i get that SIZE text to sit in the middle but keep the line expanded also can it be done through the xaml code instead of c# code
cheers.
Align the text left or right Select the text that you want to align. On the Home tab, in the Paragraph group, click Align Left or Align Right .
You can use TextColor and TitleColor to change the font color and HeightRequest to change the size.
Picker control is a view control for picking an element in a list. The visual representation of a Picker control is similar to an entry control, but a Picker control appears in place of a keyboard.
UPDATE***
Actually is very easy:
<Picker Title="Selecione o bairro" HorizontalTextAlignment="Center"/>
...OLD
You need to use a CustomRenderer
for this.
ANDROID
[assembly: ExportRenderer(typeof(BetterPicker), typeof(BetterPickerRenderer))]
namespace MDWS.Droid
{
public class BetterPickerRenderer : PickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.Gravity = GravityFlags.CenterHorizontal;
}
}
}
}
IOS:
[assembly: ExportRenderer(typeof(BetterPicker), typeof(BetterPickerRenderer))]
namespace YourNameSpace.iOS
{
public class BetterPickerRenderer : PickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.TextAlignment = UITextAlignment.Center;
}
}
}
}
I am afraid you will have to implement a CustomRenderer
for this.
For each platform OnElementChanged
you will have to set the alignment for Picker
's title.
Luckily this topic is very nicely explained in official guide.
P.S.: Welcome to stackoverflow.com, please take a moment to read this post which nicely explains why posting a screenshot of code is a bad practice.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With