如何在 Xamarin 表单中更改 Picker 字体颜色和大小? [英] How to change Picker font colour and size in Xamarin forms?

查看:42
本文介绍了如何在 Xamarin 表单中更改 Picker 字体颜色和大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Xamarin 的新手,我目前正在 Xamarin Forms PCL 中做一个项目.

I'm new to Xamarin and I'm currently doing a project in Xamarin Forms PCL.

有没有办法改变 Picker 的字体颜色和大小?

Is there a way to change the font colour and size of Picker?

  <Picker x:Name="pkr_color" Grid.Row="4" Grid.Column="1" HorizontalOptions="FillAndExpand"
    BackgroundColor="#ededed" Title="Select Color">
      <Picker.Items>
        <x:String>Red</x:String>
        <x:String>Blue</x:String>
        <x:String>Green</x:String>
      </Picker.Items>
    </Picker>

提前致谢!

推荐答案

可以使用 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.

这篇关于如何在 Xamarin 表单中更改 Picker 字体颜色和大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆