How can I create a PasswordBox with an input scope that accepts only numbers?

DaveDev

This seems like a glaring oversight in Windows Phone. The <PasswordBox /> control doesn't allow for specifying InputScope.

I need to show the PasswordBox as part of a custom password entry screen (e.g. images and buttons), and show a numeric keypad to allow only numeric input.

Coding4Fun's PasswordInputPrompt allows for numeric input but it's not customizable, in that I can't build a custom layout around it, it only allows for Title & Message values.

Is there any way for me to do this?

jack moseley

Your best off just creating your own user control.

The xaml would look something like:

<Grid x:Name="LayoutRoot">
    <TextBox x:Name="PasswordTextBox" InputScope="Number" MaxLength="{Binding MaxLength, ElementName=UserControl}" KeyUp="PasswordTextBox_KeyUp"/>
</Grid>

and the code behind could be something like:

public partial class NumericPasswordBox : UserControl
{
    #region Password 

    public string Password
    {
        get { return (string)GetValue(PasswordProperty); }
        set { SetValue(PasswordProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Password.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty PasswordProperty =
        DependencyProperty.Register("Password", typeof(string), typeof(NumericPasswordBox), new PropertyMetadata(null));

    #endregion

    #region MaxLength

    public int MaxLength
    {
        get { return (int)GetValue(MaxLengthProperty); }
        set { SetValue(MaxLengthProperty, value); }
    }

    // Using a DependencyProperty as the backing store for MaxLength.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty MaxLengthProperty =
        DependencyProperty.Register("MaxLength", typeof(int), typeof(NumericPasswordBox), new PropertyMetadata(100));

    #endregion

    public NumericPasswordBox()
    {
        InitializeComponent();
    }

    private void PasswordTextBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
    {
        Password = PasswordTextBox.Text;

        //replace text by *
        PasswordTextBox.Text = Regex.Replace(Password, @".", "●");

        //take cursor to end of string
        PasswordTextBox.SelectionStart = PasswordTextBox.Text.Length;
    }
}

You can customize all you want from then on however you wish, using dependency properties like MaxLength, shown in the example.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

SwiftUI - How to create TextField that only accepts numbers

From Dev

How can I define an Elisp widget type that only accepts positive numbers?

From Dev

How do I define a data type that only accepts numbers?

From Java

How do I make a textbox that only accepts numbers?

From Dev

How do I create an input that can only receive strings?

From Dev

PowerShell: How can I pipeline objects to a parameter that accepts input "ByPropertyName"?

From Dev

How can I make a TextBox accepts only numeric values?

From Dev

Input text field that only accepts numbers dash numbers

From Dev

I create input fields based on my fetched data, but how can I only target the input fields with a value

From Dev

How can i prevent a user from entering only numbers in an input field

From Dev

Input text field that only accepts numbers AND the dash character

From Dev

Input text field that only accepts numbers AND the dash character

From Dev

How can I create the cycle of numbers?

From Dev

How can I create the cycle of numbers?

From Dev

How can I create a list of numbers in a combobox?

From Dev

how can create specific input type on edittext? The input accettable is Roman numbers M D C X V I

From Dev

How can I write a parser using Parsec that only accepts unique elements?

From Dev

How can I create a scope function the return json in Angular?

From Dev

How to Limit Input to Numbers Only

From Dev

How to validate a input to numbers only

From Dev

How can I create a Perl subroutine that accepts more than one block?

From Dev

How can I create a C++ constructor that accepts a variable number of int's

From Dev

How can I create a function prototype in C++ which accepts two integers as parameters and returns their difference?

From Dev

How can I create a catch that ensures nothing other than a number is entered into a textbox but also accepts a blank entry

From Dev

How can I create a C++ constructor that accepts a variable number of int's

From Dev

How can I create a function which accepts a function with specific parameters as an argument?

From Dev

How can I restrict input on html to numbers with decimals using javascript?

From Java

How can I print out only odd numbers in an addition loop?

From Dev

How can I display only prime numbers in this code?

Related Related

  1. 1

    SwiftUI - How to create TextField that only accepts numbers

  2. 2

    How can I define an Elisp widget type that only accepts positive numbers?

  3. 3

    How do I define a data type that only accepts numbers?

  4. 4

    How do I make a textbox that only accepts numbers?

  5. 5

    How do I create an input that can only receive strings?

  6. 6

    PowerShell: How can I pipeline objects to a parameter that accepts input "ByPropertyName"?

  7. 7

    How can I make a TextBox accepts only numeric values?

  8. 8

    Input text field that only accepts numbers dash numbers

  9. 9

    I create input fields based on my fetched data, but how can I only target the input fields with a value

  10. 10

    How can i prevent a user from entering only numbers in an input field

  11. 11

    Input text field that only accepts numbers AND the dash character

  12. 12

    Input text field that only accepts numbers AND the dash character

  13. 13

    How can I create the cycle of numbers?

  14. 14

    How can I create the cycle of numbers?

  15. 15

    How can I create a list of numbers in a combobox?

  16. 16

    how can create specific input type on edittext? The input accettable is Roman numbers M D C X V I

  17. 17

    How can I write a parser using Parsec that only accepts unique elements?

  18. 18

    How can I create a scope function the return json in Angular?

  19. 19

    How to Limit Input to Numbers Only

  20. 20

    How to validate a input to numbers only

  21. 21

    How can I create a Perl subroutine that accepts more than one block?

  22. 22

    How can I create a C++ constructor that accepts a variable number of int's

  23. 23

    How can I create a function prototype in C++ which accepts two integers as parameters and returns their difference?

  24. 24

    How can I create a catch that ensures nothing other than a number is entered into a textbox but also accepts a blank entry

  25. 25

    How can I create a C++ constructor that accepts a variable number of int's

  26. 26

    How can I create a function which accepts a function with specific parameters as an argument?

  27. 27

    How can I restrict input on html to numbers with decimals using javascript?

  28. 28

    How can I print out only odd numbers in an addition loop?

  29. 29

    How can I display only prime numbers in this code?

HotTag

Archive