Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7549565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:58:34+00:00 2026-05-30T09:58:34+00:00

I have created custom Textbox in Silverlight 4, MVVM and PRISM 4. The custom

  • 0

I have created custom Textbox in Silverlight 4, MVVM and PRISM 4. The custom text box has dynamic behavior link it dynamically set TextMode to either Password or Text.

This is working perfect. ( if i am bind TextMode static)

<control:PasswordTextBox x:Name="customTextBox2" Width="100" Height="30" Grid.Row="4" Grid.Column="1" Text="{Binding Email}"  TextMode="Password"/>

This is giving me an error (if i am binding with dynamic)

<control:PasswordTextBox x:Name="customTextBox1" Width="100" Height="30" Grid.Row="4" Grid.Column="1" Text="{Binding Email}"  TextMode="{Binding WritingMode}"/>

following is my ViewModel code

[Export]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class UserRightsViewModel : NotificationObject, IRegionMemberLifetime
    {
 private Mode _writingMode = Mode.Text;
public Mode WritingMode
        {
            get { return _writingMode; }
            set
            {
                _writingMode = value; RaisePropertyChanged("WritingMode");
            }
        }

[ImportingConstructor]
        public UserRightsViewModel(IEventAggregator eventAggregator, IRegionManager regionManager)
        {
UserSecurity security = new UserSecurity();
            FormSecurity formSecurity = security.GetSecurityList("Admin");
formSecurity.WritingMode =  Mode.Password;
}
}

following is the enum

namespace QSys.Library.Enums
{
    public enum Mode
    {
        Text,
        Password
    }
}

following code for Custom PasswordTextBox

namespace QSys.Library.Controls
{
    public partial class PasswordTextBox : TextBox
    {
        #region Variables
        private string _Text = string.Empty;
        private string _PasswordChar = "*";
        private Mode _TextMode = Mode.Text;
        #endregion

        #region Properties
        /// <summary>
        /// The text associated with the control.
        /// </summary>
        public new string Text
        {
            get { return _Text; }
            set
            {
                _Text = value;
                DisplayMaskedCharacters();
            }
        }
        /// <summary>
        /// Indicates the character to display for password input.
        /// </summary>
        public string PasswordChar
        {
            get { return _PasswordChar; }
            set { _PasswordChar = value; }
        }
        /// <summary>
        /// Indicates the input text mode to display for either text or password.
        /// </summary>
        public Mode TextMode
        {
            get { return _TextMode; }
            set { _TextMode = value; }
        }
        #endregion

        #region Constructors
        public PasswordTextBox()
        {
            this.TextChanged += new TextChangedEventHandler(PasswordTextBox_TextChanged);
            this.KeyDown += new System.Windows.Input.KeyEventHandler(PasswordTextBox_KeyDown);
            this.Loaded += new RoutedEventHandler(PasswordTextBox_Loaded);
        }
        #endregion

        #region Event Handlers
        void PasswordTextBox_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            //this.TextChanged += ImmediateTextBox_TextChanged;
        }
        public void PasswordTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (base.Text.Length >= _Text.Length) _Text += base.Text.Substring(_Text.Length);
            DisplayMaskedCharacters();
        }
        public void PasswordTextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            int cursorPosition = this.SelectionStart;
            int selectionLength = this.SelectionLength;
            // Handle Delete and Backspace Keys Appropriately
            if (e.Key == System.Windows.Input.Key.Back || e.Key == System.Windows.Input.Key.Delete)
            {
                if (cursorPosition < _Text.Length)
                    _Text = _Text.Remove(cursorPosition, (selectionLength > 0 ? selectionLength : 1));
            }
            base.Text = _Text;
            this.Select((cursorPosition > _Text.Length ? _Text.Length : cursorPosition), 0);
            DisplayMaskedCharacters();
        }
        #endregion

        #region Private Methods
        private void DisplayMaskedCharacters()
        {
            int cursorPosition = this.SelectionStart;
            // This changes the Text property of the base TextBox class to display all Asterisks in the control
            base.Text = new string(_PasswordChar.ToCharArray()[0], _Text.Length);
            this.Select((cursorPosition > _Text.Length ? _Text.Length : cursorPosition), 0);
        }
        #endregion

        #region Public Methods
        #endregion
    }
}

I am getting following error if i am binding with dynamically.

Set property ‘QSys.Library.Controls.PasswordTextBox.TextMode’ threw an exception. [Line: 40 Position: 144]

Your answer would be appreciated.
Thanks in advance.
Imdadhusen

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:58:36+00:00Added an answer on May 30, 2026 at 9:58 am

    Try to change in your PasswordTextBox class

    public Mode TextMode
    {
        get { return _TextMode; }
        set { _TextMode = value; }
    }
    

    to

    public static readonly DependencyProperty TextModeProperty =
                DependencyProperty.Register("TextMode", typeof(Mode), typeof(PasswordTextBox), new PropertyMetadata(default(Mode)));
    
    public Mode TextMode
    {
        get { return (Mode) GetValue(TextModeProperty); }
        set { SetValue(TextModeProperty, value); }
    }
    

    You can read more here:

    • Dependency Properties Overview
    • DependencyProperty Class

    The main paragraph from the second link is:

    A DependencyProperty supports the following capabilities in Windows
    Presentation Foundation (WPF):

    ….

    • The property can be set through data binding. For more information about data binding dependency properties, see How to: Bind the
      Properties of Two Controls.

    I provide links for WPF, but basically for Silverlight it’s the same

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom component. I add a dynamic input text box to
I have created a custom message box with a textbox for input which appears
I have created a custom control inheriting TextBox . This custom control is a
I have created custom component for displaying text with either Simple or Password mode,
I have created Custom User Control which contain TextBox and PasswordBox. it is binding
i have textbox controls that are created dynamically in the ASP.NET. I want to
I have created a custom TextBox control which also contains a RequiredFieldValidator. Everything works
I have made one custom user control (search text box), which basically consists of
I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and I
friends, i have created custom title bar using following titlebar.xml file with code <?xml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.