2
votes

So in WPF and Silverlight you could set the caret color for TextBox using TextBox.CaretBrush, but in WinRT it seems in all their wisdom they removed this property. So now if the TextBox is a dark color, since it defaults the caret color to black you can't see it, and if the background color of your TextBox is black the caret ceases to exist completely. I find this completely illogical, there has got to be a way to change the caret color, either pragmatically or something?

Does anyone have any ideas?

3
Sounds like you just need to edit the right properties in the control template. I believe for WinRT it's in like *generic.xaml but I'm not positive that's the correct resource dictionary, hence not put as an answer though I'm pretty sure that's all you need to do.Chris W.

3 Answers

3
votes

This is not possible. You need to switch your TextBox to light background when it has focus so the caret is visible.

1
votes

A little late to the party on this question but I ran into the same issue and found an easy work-around. On the Windows 8.1 RT preview I noticed that overriding the TextBoxForegroundThemeBrush changes the caret or cursor color for TextBox.

<SolidColorBrush x:Key="TextBoxForegroundThemeBrush" Color="#FFFFFFFF" />

Typically the cursor is always black, even when you override the Style and ControlTemplate. I happened to stumble on this by looking in the ThemeResources.xaml that Filip mentioned above. I'm not sure if this applies to pre-8.1 xaml, Microsoft seems to have cleaned a lot up in new SDK.

0
votes

I got this working by overlaying a transparent canvas overtop of the TextBox, using SelectionStart and GetRectFromCharIndex to obtain coordinates, then on KeyDown, KeyUp, and MouseDown I set the coordinates of a Line and use a TranslateTransform to move it, works great and performance is fantastic!

Not sure why I didn't try this first, I've done Transforms in Silverlight and WPF many times prior. I guess the subtle differences in WinRt kind of threw me for a loop...