TextBox doesnt allow user to type - wpf

Hello everyone what I'm trying is in wpf to make that user cant type in textbox. I know there is way just to make it isEnabled = False but if i use it my textbox gets grey color and i cant make it without background! So is there anyway to forbid user entering any char in textbox or any other way? Please help

Use the TextBox.IsReadOnly property: http://msdn.microsoft.com/en-us/library/ms753374.aspx

Did you want to dynamically change when the textbox is editable or is it always going to be un-editable? You might consider using a label instead if this is the case. If its dynamic you probably want the backcolor to change to let the user know this is the case.

Related

How do I pick right TextBox to input value in it

Need help in achieving functionality for the image that I insert.
I have 4-5 textboxes and near them some type of calculator.
All TextBoxes are bound to properties in ViewModel.
All calculator buttons use Command="{Binding AddNumberCommand}" CommandParameter="9" for passing value to a property.
Problem is that I don't know how to pick the right TextBox for inputting value.
Thanks for the advice.
There are a couple ways I could think of to do this. Note that whichever way you do it, I'm pretty sure you'll have to set Focusable to false on all your Buttons, otherwise they'll steal the focus away from the TextBoxes when clicked.
Keyboard Focus Events
You could declare a field where you track the currently focused TextBox (e.g. private TextBox focusedBox;). And for each TextBox, you could handle the GotKeyboardFocus and LostKeyboardFocus events. You could use those events to track which TextBox currently has focus, and when you want to add a number you just add it to focusedBox.
You would also have to check if focusedBox is null, in case none of your TextBoxes are currently focused.
This method would ensure that the calculator buttons only ever effect those TextBoxes you want them to.
Keyboard.FocusedElement
Alternatively, you could just use the Keyboard.FocusedElement static property. This will point to whatever element currently has keyboard focus. This coud be any focusable element in your application, or null if the keyboard focus is outside your application.
You could attempt to cast Keyboard.FocusedElement to TextBox, and if the cast succeeds, append the text.
This would require much less code, but also allows the buttons to add text to any TextBox in your application. This may or may not be a problem, and could be prevented by setting some unique property on the TextBoxes you want to allow input on and checking for it, or keeping a list of said TextBoxes.

Overridding a universal app's textbox enter style

I'm trying to create a universal Windows 10 app.
I have this textbox, that should be invisible. The user must simply be able to enter text at the point.
The only thing I have done is set the background equal to the app's background and no border.
The result is ok, but when I enter the textbox, it becomes white, like a normal textbox.
Anyone who knows how to fix this. I want the textbox to remain the same.
Thanks in advance
Kind regards
You have to create a new Style for your textbox. It will overwrite the default template and behaviour or the default TextBox. Here is the default template: https://msdn.microsoft.com/en-us/library/windows/apps/mt299154.aspx
And here is code sample: https://stackoverflow.com/a/24432861/1279342

Silverlight - I need to know Selected Text in a PasswordBox

I'm building a complex change password form, but I need a simple task to continue my work:
I need to know what text is selected in a PasswordBox.
I know how to do it in TextBox components, using SelectedText, but I can't in a PasswordBox.
Have you some solutions to this problem?
Thank you

DevExpress MemoEdit selection backcolor

I'm trying to achieve a similar functionality as with RichTextBox while using the MemoEdit control.
With RichTextBox it's possible to use .Select() in order to select part of the text then use .SelectionBackColor() in order to change the backcolor only for the selected text while the rest of the text still has the same color. Sadly I wasn't able to achieve this since the MemoEdit control doesn't appear to have any similar methods for achieving this.
Anyone managed to get anything similar working using MemoEdit or has a good alternative (that allows the control to still be able to use the form skin) ?
Thanks in advance.

Mimicing the tab key being pressed in Silverlight TextBox KeyDown event

Title pretty much explains it all really. I need to know how to automatically jump to the next element (the element that would get focus if the user presses the "Tab" key), whatever that may be, in the KeyDown event of a Silverlight TextBox. My TextBoxes are generated dynamically so I can't, for example, manually code TextBox1 to set focus on TextBox2 on keydown etc. Any help would be greatly appreciated
I don't believe there is an easy way to accomplish this. The only method I know of is to use the VisualTreeHelper and get all the elements and then loop through them by their tab stop values.
If your textboxes are generated dynamically you could use a Behavior to set their tab stop properties pretty easily which would be a much better solution. Or just set it when you create them.

Resources