PasswordBox InputScope

5 posts, 0 answers
  1. ömer
    ömer  avatar
    3 posts
    Member since:
    Mar 2014

    Posted 19 Mar 2014 Link to this post

    Hi

    I am working on a WP8 project 
    I am using passwordbox and I want number keyboard appear.
    I tried inputScope like in the textbox but there is no property named InputScope. 
    is there any way? 

    thanks.
  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 21 Mar 2014 Link to this post

    Hello,

    Thank you for your question.

    This is not possible. The InputScope is available only for the TextBox (and RadTextBox respectively). Neither RadPasswordBox, nor the native PasswordBox has this option and the framework doesn't provide a way to manipulate the layout (and the type) of the keyboard that is used.

    Regards,
    Todor
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
  3. DevCraft banner
  4. Eugeniy
    Eugeniy avatar
    60 posts
    Member since:
    Feb 2011

    Posted 01 Oct 2014 Link to this post

    This is an example how to set InputScope to Number. Add property and a bit more logic if you want to set any input scope you want:

    01.public class NumericPasswordBox : RadPasswordBox
    02.    {
    03.        private TextBox _passwordTextBox;
    04. 
    05.        public override void OnApplyTemplate()
    06.        {
    07.            base.OnApplyTemplate();
    08. 
    09.            _passwordTextBox = GetTemplatePart<TextBox>("PART_PasswordTextBox");
    10. 
    11.            var inputScope = new InputScope();
    12.            inputScope.Names.Add(new InputScopeName
    13.            {
    14.                NameValue = InputScopeNameValue.Number
    15.            });
    16.            _passwordTextBox.InputScope = inputScope;
    17.        }
    18. 
    19.        protected override void OnGotFocus(RoutedEventArgs e)
    20.        {
    21.            base.OnGotFocus(e);
    22.            _passwordTextBox.Focus
    23.        }
    24.    }
  5. Eugeniy
    Eugeniy avatar
    60 posts
    Member since:
    Feb 2011

    Posted 01 Oct 2014 in reply to Eugeniy Link to this post

    sorry, _passwordTextBox.Focus(); - at the end
  6. Eugeniy
    Eugeniy avatar
    60 posts
    Member since:
    Feb 2011

    Posted 10 Oct 2014 Link to this post

    Here is a little bit different solution:

    public class NumericPasswordBox : RadPasswordBox
    {
        public NumericPasswordBox()
        {
            PeekButtonVisibility=Visibility.Collapsed;
        }
     
        private TextBox _passwordTextBox;
        private PasswordBox _passwordBox;
     
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
     
            _passwordTextBox = GetTemplatePart<TextBox>("PART_PasswordTextBox");
            _passwordBox = GetTemplatePart<PasswordBox>("PART_PasswordBox");
            _passwordBox.IsHitTestVisible = false;
     
            var inputScope = new InputScope();
            inputScope.Names.Add(new InputScopeName
            {
                NameValue = InputScopeNameValue.Number
            });
            _passwordTextBox.InputScope = inputScope;
        }
     
        protected override void OnGotFocus(RoutedEventArgs e)
        {
            base.OnGotFocus(e);
            _passwordTextBox.Focus();
            _passwordTextBox.Opacity = 1;
            _passwordBox.Opacity = 0;
        }
     
        protected override void OnLostFocus(RoutedEventArgs e)
        {
            base.OnLostFocus(e);
     
            _passwordTextBox.Opacity = 0;
            _passwordBox.Opacity = 1;
        }
    }
Back to Top
DevCraft banner