wpf - WPF:TextBox中边框和文本之间的空间
解决方案
当您使用 Snoop 之类的工具检查可视化树时,您可以看到其中包含TextBox
渲染实际内容的内容(1)内部类处理文本框中内容的渲染,默认情况下设置左右边距到“2”(2)。我不认为您可以设置自身的样式来覆盖默认边距值,但由于它在内部设置为“2”,您可以放心地将 Textbox 上的 Padding 设置为“-2,0”就可以了。Border
ScrollViewer
ScrollContentPresenter
TextBox
TextBoxView
TextBoxView
编辑:
在TextBoxView 文档
中,您可以发现在TextBoxView
构造函数(第 38 行)中,Margin 属性设置为BidiCaretIndicatorWidth
(第 1219 行)的常量值:因此,在 TextBox 的末尾和开头留一些空间可能是有意义的,因此插入符号可以可见
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;
推荐阅读
- spring - 我应该使用 DTO 还是不使用?
- python - 将 Django 应用程序部署到 Heroku 无法加载静态文件
- html - HTML 图像映射 - 设置特定区域的覆盖文本
- java - 对象未从 ArrayList 中删除
- python - 运行以下代码时出现分段错误
- mule - 缺少 Mule 文档名称
- java - 尝试获取空数组 Kotlin 的长度
- sql-server - SAP B1:如何检查 OIVL 表中是否插入了新数据
- laravel - Laravel 6.0 输入::value"old(' ')"
- visual-studio-code - 如何在vscode中设置匹配的括号颜色?