WPF中如何实现指定控件组的缩进布局 适配Label动态宽度且不影响页面其他内容
WPF 实现表单区块缩进布局的实现咨询
需求细节
- 目标区块是长页面中第10行的独立内容,实现方案不会干扰页面其他区域的排版逻辑
- 所有
Label控件的尺寸需要根据自身文本内容动态适配,禁止通过固定百分比宽度设置标签尺寸 - 核心实现难点:让第一行内的
Label2/TextBox2、Label3/TextBox3两组控件,相对于第二行的Label5/TextBox5实现要求的缩进效果 - 参考布局为典型的分层缩进式表单结构,初始编写的代码存在逻辑疏漏,仅用于表达初步排版思路
初始编写的布局代码(存在逻辑错误)
<Grid Grid.Row="10"> <Label Grid.Row="0" Grid.Column="0" Content="Label1"/> <TextBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3"/> <Label Grid.Row="0" Grid.Column="4" Content="Label2"/> <TextBox Grid.Row="0" Grid.Column="5"/> <Label Grid.Row="0" Grid.Column="6" Content="Label3"/> <TextBox Grid.Row="0" Grid.Column="7"/> <Label Grid.Row="1" Grid.Column="0" Content="Label4"/> <TextBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3"/> <Label Grid.Row="1" Grid.Column="0" Content="Label5"/> <TextBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3"/> </Grid>
注:上述代码存在网格列定义缺失、同单元格控件重叠、部分
TextBox标签未闭合的问题,仅用于表达大致排版方向,和实际运行效果存在偏差。
内容的提问来源于stack exchange,提问作者grunt
相关产品推荐
相关产品推荐

