0

I have a MAUI app. The initial XAML markup looks like this:

<mops:PopupPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                xmlns:mops="clr-namespace:Mopups.Pages;assembly=Mopups"
                xmlns:tools="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
                xmlns:vmods="clr-namespace:LockAndKey.Pages"
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                x:DataType="vmods:DbViewModel"
                x:Class="LockAndKey.Pages.DbUpdte"
                CloseWhenBackgroundIsClicked="False"
                BackgroundColor="#80000000">

As you can see I'm using Community Toolkit for MAUI. What I'm trying to do is mask an entry control like a telephone number entry. So I have the XAML entry control like this:

<Entry Placeholder="Enter owner's phone number"
       Grid.Row="2" Margin="20,0,10,0"
       Text="{Binding DbPhone}" Keyboard="Numeric">
    <Entry.Behaviors>
        <tools:MaskedBehavior Mask="(000) 000-0000"/>
    </Entry.Behaviors>
</Entry>

And this is the data binding for the control:

public string DbPhone
{
    get => _phone;
    set
    {
        _phone = value;
        OnPropertyChanged(nameof(DbPhone));
    }
}

When I run the program and tab town to this entry control, no numeric keypad shows up, and when I enter a phone number, nothing is entered into the control. How can I fix this?

5
  • I'm curious to know which platform? Whilst Keyboard="Numeric" works inconsistently between platforms and models, knowing which platform can give some insight what you need and what workarounds you can use. Commented Nov 10 at 2:27
  • Stephen Quan, I am using Windows 11 and the framework is .net 9.0. I initially tried adding Keyboard="Numeric" and when I did that and tried to type numbers, nothing was being entered. Commented Nov 10 at 3:35
  • 1
    Keyboard="Numeric" is more likely to show a numeric keypad on Android and some iOS devices. On Windows, unless if you're using a touch screen, I'm not sure you would be expecting anything different than being able to type with the keyboard. As to the "tab" key. Dependent on the visual element tree, a combination of "tab" and/or arrow keys may be needed for keyboard navigation to the control. You need to ensure that your Entry component actually acquires active focus. I recommend that you add troubleshooting by binding to your Entry's IsFocused property and verify that it changes to True. Commented Nov 10 at 3:53
  • Since you mentioned popup, it may be necessary to call VisualElement.Focus on the Entry after the Popup opens. Commented Nov 10 at 3:58
  • I added Keyboard="Telephone" back into the control and removed the <Entry.Behaviors> coding and ran the program. A phone number that was stored in the table as 1234567890 was displayed as (123) 456-7890 Which is how I want it. However, when I delete that line and manually type it in as 1234567890 I would like it to show up as (123) 456-7890 which it doesn't. I i place that <Entry.Behaviors> back in I am not able to type any numbe at all. Commented Nov 10 at 4:13

1 Answer 1

1

MaskedBehavior require you to use X character to specify mask. In your case

<tools:MaskedBehavior Mask="(XXX) XXX-XXXX"/>

or alternatively

<tools:MaskedBehavior Mask="(000) 000-0000"
                      UnmaskedCharacter="0"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.