且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Xamarin 表单中更改 Picker 字体颜色和大小?

更新时间:2023-01-27 19:57:00

可以使用 PCL 代码更改选择器的字体大小.

Font size of a picker can be changed with PCL code.

创建 MainPage.xaml 文件

Create MainPage.xaml file

<Picker x:Name="PickerList" Title="Select Any One" IsVisible="False" SelectedIndexChanged="PickerList_SelectedIndexChanged">
        <Picker.Items>
            <x:String>Option 1</x:String>
            <x:String>Option 2</x:String>
            <x:String>Option 3</x:String>
        </Picker.Items>
    </Picker>
    <Label x:Name="PickerLabel" Text="Tap to Select Picker" FontSize="14" HorizontalOptions="Start">
        <Label.GestureRecognizers>
            <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
        </Label.GestureRecognizers>
    </Label>

创建 MainPage.xaml.cs 文件

Create MainPage.xaml.cs file

private void PickerList_SelectedIndexChanged(object sender, EventArgs e)
    {
        PickerLabel.Text = PickerList.Items[PickerList.SelectedIndex];
        // PickerLabel.Text = PickerList.SelectedItem.ToString() ;
    }

    private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
    {
        PickerList.Focus();
    }

这解决了 Android 和 IOS 的问题.

this solves the problem for Android and IOS.