Is there a way to disable Auto Capitalisation on Xamarin Forms 'Entry' XAML

為{幸葍}努か 提交于 2020-06-13 19:30:04

问题


I have just started working in Xamarin and am writing an App targeting iOS and Android. I'm trying to keep pretty much all of my UI design in the common library between them and am starting to find the lines a bit blurred. My current requirement is to disable the auto-capitalisation on the 'Entry' tag object in XAML. Is this something that can be done by markup? I cannot find any property that would support this behaviour. If not, what should I do instead?


回答1:


If you plan to use this keyboard in a number or pages you will want to add the following code to your App.xaml's ResourceDictionary. If you want to use it in multiple places but only in a single ContentPage you will want to add it to the ContentPage's ResourceDictionary. Otherwise you can add it directly to your Entry.

Also see here for available KeyboardFlag values. I am just using None below.

If adding to a ResourceDictionary:

<ContentPage.Resources>
  <ResourceDictionary>
    <Keyboard x:Key="NoCapitalizationKeyboard"
              x:FactoryMethod="Create">
      <x:Arguments>
        <KeyboardFlags>None</KeyboardFlags>
      </x:Arguments>
    </Keyboard>
  </ResourceDictionary>
</ContentPage.Resources>

<Entry Keyboard="{StaticResource NoCapitalizationKeyboard}" />

Or directly to an Entry:

<Entry>
  <Entry.Keyboard>
    <Keyboard x:FactoryMethod="Create">
      <x:Arguments>
        <KeyboardFlags>None</KeyboardFlags>
      </x:Arguments>
    </Keyboard>
  </Entry.Keyboard>
</Entry>



回答2:


You can set the Keyboard="Text" - the Default keyboard performs the capitalisation.

Also check out the additional keyboard settings that can be applied. These allow you to toggle suggestions and other things.

Alternatively I recommend you create a simple Effect for UITextField and use the native iOS APIs to set the flags you need (AutocapitalizationType = UITextAutocapitalizationType.None;).

We also have documentation on how to create a custom renderer to achieve the goal but since the introduction of effects, it seems to be a bit of an overkill.




回答3:


There's a workaround to use entry without capitalization, such as a "username". For this you can simply use

<Entry Keyboard="Email" Placeholder="Username"/>

Finally you'll get a non-autocapitalization entry and also you may use it as a email text if needed.




回答4:


A bit late but there is now a simple way to get a plain keyboard, with no flags:

<Entry
    FontSize="Small"
    Keyboard="Plain"
    Text="Text"/>

Documentation here.



来源:https://stackoverflow.com/questions/39983468/is-there-a-way-to-disable-auto-capitalisation-on-xamarin-forms-entry-xaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!