question

JeanBaptisteDelvaux-5990 avatar image
0 Votes"
JeanBaptisteDelvaux-5990 asked RobCaplan edited

How to create to show a custom keyboard

Greetings,

For my app, I show a display prompt to ask for a quantity. Before we were using a quantity of boxes, but recently we also started getting number of pallets. Since in the end it is stored as a string anyway, (that number is simply an information. It is never used for any calculation so it's simply added on a footnote) the easy solution proposed was to add a P or B after the number. My question is: How to create a custom keyboard that accept numbers and P and B?

Here's the simple line of code where I need it. Keyborad.Numerci comes from Xamarin.Forms.Keyboard.

viewModel._quantity = await DisplayPromptAsync(viewModel._quantity, "Quantité ", keyboard: Keyboard.Numeric);

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

KyleWang-MSFT avatar image
0 Votes"
KyleWang-MSFT answered KyleWang-MSFT edited

Hi JeanBaptisteDelvaux-5990,

Welcome to our Microsoft Q&A platform!

Maybe you don't need custom keyboard. Here is another workaround you can refer to. You can replace the "prompt" with "popup" which you can add your custom controls to.

You can create a custom Popup control with a Entry to let user input quantity. And add a picker to select the "boxes" or "pallets".

First, you need to install the Nuget package "Xamarin.CommunityToolkit".

Then create a "popup" content page.

 <?xml version="1.0" encoding="utf-8" ?>
 <xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
            x:Class="keyboardDemo.MyPopup"
            Size="300,100">
    
     <Grid ColumnDefinitions="*,*,*,*,*,*"
           RowDefinitions="*,*">
         <Entry Grid.ColumnSpan="4"
                Keyboard="Numeric"/>
         <Picker Grid.Column="4"
                 Grid.ColumnSpan="2"
                 Title="quantifier">
             <Picker.ItemsSource>
                 <x:Array Type="{x:Type x:String}">
                     <x:String>box(es)</x:String>
                     <x:String>pallet(s)</x:String>
                 </x:Array>
             </Picker.ItemsSource>
         </Picker>
         <Button Grid.Row="1" 
                 Grid.ColumnSpan="3"
                 Text="Cancel"/>
         <Button Grid.Row="1" 
                 Grid.Column="3" 
                 Grid.ColumnSpan="3"
                 Text="OK"/>
     </Grid>
 </xct:Popup>

Show popup:

 private void Button_Popup(object sender, EventArgs e)
 {
     Navigation.ShowPopup(new MyPopup());
 }

Regards,
Kyle


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.