Hi guys, today we are going to see how to hide textbox blinking cursor in C# and WPF. It is a very short tutorial so stay tuned.

This post will not have the usual you tube video and git hub repository because this is just a neat little trick.
Why would you like to hide TextBox blinking cursor?
Some time ago, while coding a WPF application, I needed to create a numeric type of input field. I immediately though of the NumericUpDown control I was used to using in WinForms. Well, if you are using WPF you are out of luck. The well-known control wasn’t there. As a result, I was about to create my own.
More tutorials on TechInDeep:
- How to implement Undo feature in C#
- How to create custom control in C#
- How to create round button in C#
Creating a numeric up/down control
Just to make sure I implement everything correctly, I started up a WinForms project and dropped the NumericUpDown on my test project. So, now it was time to recreate it in WPF. I guess there will be additional post/tutorial for the developers who would like to follow, but I want to turn your attention at the current problem. The blinking cursor.
While rebuilding the control I noticed one crucial difference. The original UpDown from WinForms did not have the annoying cursor blinking. You are free to input numbers or use the Up/Down buttons to set your value. And of course, because my custom control consists of TextBox – it automatically carries the carret with it. The blinking cursor posed a real problem. It is annoying to have it work like it would work in a TextBox. So, there is a very simple solution to it:
txtTextBox.CaretBrush = new SolidColorBrush(Colors.Transparent);
As you can see the TextBox has a property called CaretBrush which you can set and style. In our case we don’t style the caret as much as we want it gone. But please note that you can style it as well.
If you prefer to use XAML to set this property than it is quite easy too:
<StackPanel>
<!--Setting the Caret to Blue color-->
<TextBox CaretBrush="Blue" Text="HelloWorld" />
<!--Setting the Caret to Green color-->
<TextBox CaretBrush="Green" Text="HelloWorld" />
</StackPanel>

Conclusion
Well, I hope this little tutorial on how to hide TextBox blinking cursor will help you in your project. You can also use this code as a reference if you would like to style the caret in your own way.
Next time, we will re-create the UpDown control as is from Windows Forms.