I have TextBox for entering a file name. With a long path the TextBox can only show a part of the path. I consider the rightmost part (containing the file name) more relevant than the left part. However the TextBox displays only the leftmost part. I thought HorizontalContentAlignment would do the trick but it doesn't. What can I do?
Asked
Active
Viewed 2,898 times
4
-
Can you share the code please? If I create a simple application with `
-
Not sure that would be possible, with TextBox, try to build your own control – AymenDaoudi Apr 11 '15 at 20:06
-
@Szabolcs: It's just a TextBox as you made. If the text does not fit into the TextBox and you finish entering text you do not see the right end, do you? – Johannes Schacht Apr 11 '15 at 20:30
1 Answers
3
As mentioned in the comments, the TextBox
will automatically do what you want as you start typing into it, but I'm guessing that you also want it to do this if you set the Text from the designer (or programmatically).
Consider the following markup:
<TextBox Width="50" Height="30" Name="MyTextBox">This is some text</TextBox>
When executed, this will show the left portion of the text. To show the right portion, you could do something like this in your code behind:
public MainWindow()
{
InitializeComponent();
// The text box needs to have the focus for Select to work
MyTextBox.Focus();
// Move the caret to the end of the text box
MyTextBox.Select(MyTextBox.Text.Length, 0);
}
This example shows doing this in the constructor for the window, but you can do it wherever makes sense in your application.

Gary Wright
- 2,441
- 1
- 20
- 32