How to make a textbox with set width in pixels, with no overflow text?
I'm looking to create a single line textbox in WPF with a very precise width (in pixels), with no scrolling or overflow text. The width should be able to be set in pixels, not units (96/inch). I want the user to be unab开发者_C百科le to add additional characters to the textbox if the current text fills the textbox entirely.
What sort of properties should I set to get behavior as described above?
You can set the MaxLength property of your textbox like this(It will restrict the length of text to 3 in your textbox) -
<TextBox MaxLength="3"/>
You can even bind this property with your own ViewModel property. In case you want to bind it to the width of your textbox if you don't want to hardcode the value you can bind it to Actual Width of your textbox -
<TextBox MaxLength="{Binding ActualWidth, RelativeSource={RelativeSource Mode=Self}}"/>
精彩评论