Reputation: 3875
is there a way to allow editing a string partially in c# and wpf textbox? somthing , if the contents of the TextBox were for example
"http://xxxx.xxx/xx/path?param1=xxx¶m2=xxx"
the x can be replaced with whatever length but any thing else is constant and cannot be edited in the textbox, any way to achive such thing?
Upvotes: 1
Views: 392
Reputation: 69985
There are two relevant events that you can handle on the TextBox
; the PreviewKeyDown
and the PreviewTextInput
events. By handling these two events, you will have complete control over what the user can and can't edit in the TextBox
. Of course you will need to work out the logic inside, but the event handlers are the tool to enable you to do what you want:
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
// Do your text filtering here using e.Key and e.Handled
}
private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
// Do your text filtering here using e.Text and e.Handled
}
Upvotes: 2