Eyeshot WPF中按用户输入设置尺寸小数位数问题求助
问题解决:Eyeshot WPF 尺寸标注最终输出小数位数不生效
问题现象
在Eyeshot WPF视口中实现尺寸标注时,交互式预览阶段能按用户输入的小数位数显示(如输入1则显示1.3),但最终添加到视口的尺寸实体却恢复为原始未四舍五入的数值。
原因分析
Eyeshot的Dimension实体默认开启自动文本更新(AutoText属性默认为true),当手动设置dim.Text后,实体内部会自动重新计算尺寸值并覆盖自定义文本,导致最终显示原始数值。
解决方法
方法1:禁用自动文本更新
通过设置AutoText = false,阻止系统自动覆盖自定义文本,确保手动设置的四舍五入数值生效:
修改snapping.cs中的代码:
else if (entity is Dimension) { Dimension dim = (Dimension)entity; dim.LayerName = layerName; dim.WidthFactor = 0.9; dim.LineWeightMethod = colorMethodType.byEntity; // 禁用自动文本更新,保留自定义文本 dim.AutoText = false; double d1 = dim.Distance; double newDistance = Math.Round(d1, Roundoffno); dim.Text = $"D {newDistance}"; Entities.Add(dim); }
方法2:使用内置格式字符串(推荐)
利用Dimension的FormatString属性直接指定小数位数格式,无需手动计算四舍五入,同时保持自动更新特性(后续几何对象修改时,尺寸会自动更新并维持指定格式):
修改snapping.cs中的代码:
else if (entity is Dimension) { Dimension dim = (Dimension)entity; dim.LayerName = layerName; dim.WidthFactor = 0.9; dim.LineWeightMethod = colorMethodType.byEntity; // 设置格式字符串,{0}代表尺寸数值,F{Roundoffno}表示保留Roundoffno位小数 dim.FormatString = $"D {{{0}:F{Roundoffno}}}"; Entities.Add(dim); }
注意事项
- 方法1适合需要完全自定义文本内容(如添加特殊前缀、后缀)的场景,但后续几何对象修改时,尺寸数值不会自动更新。
- 方法2更符合Eyeshot的设计逻辑,既保证小数位数控制,又保留尺寸的自动更新能力。
内容的提问来源于stack exchange,提问作者Dark knight
相关产品推荐
相关产品推荐

