Is there a way to hide the cursor in a WPF textbox? I know there is Cursor="None" but that only affects the mouse cursor. I want to hide the "text cursor".
Caret is the current insert position in a text editor. Cursor is the shape of the mouse cursor.
There is no way to disable the caret in a read-write TextBox. Instead, change the CaretBrush to be transparent.
TextBox txt = ...;
// Hide the caret.
txt.CaretBrush = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
// Show the caret.
txt.CaretBrush = null; // use default Brush
You can colour the cursor the same colour as the background or Transparent using the TextBox.CaretBrush property.
Related
I have a TextBox with Width equals the width of a letter 'A'. But the letter is not displayed correctly.
Is it possible to avoid space between a border and the beginning of 'A'? Padding="0" does not help.
Example:
When you inspect visual tree with a tool like Snoop you can see that TextBox consists of Border that contains ScrollViewer that among others have ScrollContentPresenter that renders actual content of the TextBox with TextBoxView (1) internal class handling the rendering of content in the textbox and by default left and right margin set to "2" (2).
I don't think you can style the TextBoxView itself to override default margin values but as it is internally set to "2" you can safely assume that setting Padding on Textbox to "-2,0" will be fine.
Edit:
In TextBoxView documentation
you can find that in TextBoxView constructor (line 38) there is Margin property set to the constant value of BidiCaretIndicatorWidth (line 1219):
So probably it make sense to leave some space at the end and the beginning of the TextBox so the caret can be visible
static TextBoxView()
{
// Set a margin so that the bidi caret has room to render at the B edges of content.
MarginProperty.OverrideMetadata(typeof(TextBoxView), new FrameworkPropertyMetadata(new Thickness(CaretElement.BidiCaretIndicatorWidth, 0, CaretElement.BidiCaretIndicatorWidth, 0)));
}
(...)
// BiDi caret indicator width.
internal const double BidiCaretIndicatorWidth = 2.0;
What is the name of the element of a text box control which I need to manipulate to achieve a change of the color of the position marker in the text box?
The normal foreground attribute changes the actual texts color, but the position marker stays the same color.
To modify the color of the caret (which assume is what you call "positionmarker") you have to set the CaretBrush property of the TextBox.
I have a Grid in silverlight having a lot of different controls.
In the last row of Grid, I have a RichTextBox.
To write something in RichTextBox, first we have to scroll down to that because controls are too much.
Each time we open that Grid, all the controls are initiated with some initial data.
Now there is a problem with this line
this.rtb.Selection.Text = "Initial Text";
What this line do is, it set text into RichTextBox control and also set focus on it, as a result my scroll bar move to the bottom, which is very annoying.
I want this text assigned to it but scroller should stay at top.
Try this:
// create a paragraph
Paragraph prgParagraph = new Paragraph();
// create some text, and add it to the paragraph
Run rnMyText = new Run();
rnMyText.Text = "This is some example text with a ";
prgParagraph.Inlines.Add(rnMyText);
// add the paragraph to the RTB
rbtMyRichTextBox.Blocks.Add(prgParagraph);
I am dynamically adding text in a RichTextBox.
How can I set Focus on the last line so the user can see it?
This will move the caret to the last line:
richTextBox.CaretPosition = richTextBox.Document.ContentEnd;
But it will not scroll the richTextBox to make the caret visible. To accomplish that you also have to call ScrollToEnd():
richTextBox.CaretPosition = richTextBox.Document.ContentEnd;
richTextBox.ScrollToEnd();
I have a child Window , and I am displaying it from the code behind as below:
ChildPhotoViewer PhotoViewer = new ChildPhotoViewer();
PhotoViewer.DataContext = selectedPhoto;
PhotoViewer.Title = selectedPhoto.strTitle.ToString();
PhotoViewer.Show();
But While Displaying the child window I am getting the Close Button and a Border thickness arround the Window.
I am able to hide the Close Button but is there a way to hide the thickness(Border) across the child window.
Edit:
![alt text][1]
In the Image , there is border arround image after Collpasing the Close button and making
PhotoViewer.Title = null;
PhotoViewer.HasCloseButton = false;
I want to get rid of that Rectangular Border.
Have you tried:-
PhotoViewer.BorderThickness = new Thickness(0);
Edit
Perhaps you are refering to the title block across the top of the window?
PhotoViewer.Title = null;
PhotoViewer.HasCloseButton = false;
Edit
Third attempt.
The template for ChildWindow place the content in border with a 7 pixel margin. This also has an outer border which has a White background. That is what you are seeing in the image. The only way to eliminate it is to copy the ChildWindow template and edit it.
Depends on what you mean by the Border.
If you have a look at the Documentation you can see there is a border (with a thickness of 1) around the edge of the entire window that can be altered like Anthony mentions.
However there is also the window Chrome which in the default template has a number of borders. To change the thickness of these borders you will need to create a style without the borders being present.