views:

404

answers:

2

Need to make a new WPF control and give the Caret to it. In WINFORMS or previos Windows UI it was easy using the WIN API Caret functions, but now in WPF we don't have hwnd for each control so... is there a way to do it?

+2  A: 

In WPF, the caret is actually CaretElement, an internal FrameworkElement used for rendering selection blocks and the caret.

If you do not inherit from some sort of control which already offers caret support and try to manipulate it, sadly, you could be facing the need to implement it from scratch.

EDIT

The CaretElement is internal to the framework and yes, not documented.

It is mentioned here, for example.

A closed source custom implementation exists in a commercial package.

kek444
That CaretElement is not documented , not even accessible right?
jmayor
Edited answer for completeness.
kek444
A: 

Caret in WPF is an just another animation, no special API for that. Draw a line, and change its opacity with DoubleAnimation.

If you have closer look at WPF TextBox, the caret doesn't even do 'pixel inversion', it's just gray line drawn over the letter.

Potentially you can do pixel inversion in WPF, by implementing a pixel shader effect. Not worth it probably. VS2010 beta doesn't do inversion for text caret.

Apart from TextBox/RichTextBox there are 3 other editing components you can find:

  • Expression Blend code editor
  • Visual Studio 2010 code editor
  • SharpDevelop 4 code editor
Oleg Mihailik
Ok, it is tricky... and then TExt should be handled by the TextInput event as well as Preview/KeyDow/UP events. It's a nightmare to make it from scratch.... Thanks for the help. All of you guys.
jmayor
It certainly is a good quality nightmare.
Oleg Mihailik